Compare commits
177 commits
alfar
...
localisati
| Author | SHA1 | Date | |
|---|---|---|---|
| b1f3a6d666 | |||
| 2f8f399b43 | |||
| eb793cfb57 | |||
| 0668d59a9b | |||
| 555830351d | |||
| b431bb9d1f | |||
| a5d3b54dd6 | |||
| ffed6fd33e | |||
| 1954867385 | |||
| 088d969323 | |||
| 91f2a8bc0a | |||
| 0b90201368 | |||
| caaa233392 | |||
| 842af2fd4f | |||
| b4a6432617 | |||
| 2d865f5bb0 | |||
| 6ddca72144 | |||
| 7a618936f2 | |||
| 811e4cac34 | |||
| cae18b440d | |||
| c1c1c76360 | |||
| 4ee98d90cb | |||
| fdc5d9fab7 | |||
| d9bca1934f | |||
| b8ddcfd1d5 | |||
| eeebfd4d06 | |||
| 064708d844 | |||
| 0008e0b34e | |||
| 5530f7dc3d | |||
| bb1769b876 | |||
| 2b1064025a | |||
| ceb0d0e35a | |||
| 446fcc7327 | |||
| a538e3d5e4 | |||
| 19281e31ce | |||
| 2ac22d7d86 | |||
| 71721caa8d | |||
| 9204dc96a2 | |||
| 9ed606a9aa | |||
| 4c7e0ec16d | |||
| 42c1e7ddd3 | |||
| aa252c86ca | |||
| 93d5b5424e | |||
| 94b66f29ee | |||
| ec3775a304 | |||
| af58fcec0d | |||
| 0f5b5e4868 | |||
| 038d827991 | |||
| 85c7af6d05 | |||
| 9bd98c68c3 | |||
| 78d75a4a84 | |||
| b16d1775d8 | |||
| b25548280c | |||
| 106dc22bc1 | |||
| 4cf95fa8c7 | |||
| 56edb02eab | |||
| ec533fdbd9 | |||
| 2125e71682 | |||
| 0d1f655598 | |||
| 38bb8f1813 | |||
| 036596b80d | |||
| 778451bed8 | |||
| 06cc1d8c88 | |||
| b661fa6516 | |||
| 97e25dabe9 | |||
| 46805836f3 | |||
| 16cacde532 | |||
| e87b85597d | |||
| b870dc65b0 | |||
| dc24cbbacd | |||
| 1420db796b | |||
| 9da27b64d3 | |||
| a7cb4b45a7 | |||
| ecf6e1bedb | |||
| 2147c892b0 | |||
| 172ed331e5 | |||
| 0fe91dd52f | |||
| 578ecbb591 | |||
| 00a30d9b34 | |||
| 7ec4a14ed4 | |||
| 6f439f37c3 | |||
| fc5d6b8abc | |||
| be8c7c59d3 | |||
| 9117c0b251 | |||
| 1c4d1c7b6a | |||
| a2737dc245 | |||
| c5387421d4 | |||
| a6df7a47f8 | |||
| d142fad330 | |||
| beffd0bee6 | |||
| dd92bdf345 | |||
| a3d4f4ca02 | |||
| 62ebc13116 | |||
| 162f71c39d | |||
| 788e226372 | |||
| 84aba227eb | |||
| ed7483568c | |||
| 3b194eaec9 | |||
| 4cb9b7788d | |||
| 7a43ced3fb | |||
| 3dae107b85 | |||
| ac4ce4c636 | |||
| ffb45d1c1c | |||
| 87db3e03a6 | |||
| fdc0fdcedc | |||
| 3c81b8f130 | |||
| 504e6e83ed | |||
| 4862f47e73 | |||
| b7b9cbcbd5 | |||
| 99ec4134be | |||
| bba81cbbf0 | |||
| 373b0069dd | |||
| e972ca5ea4 | |||
| 356e0f44d8 | |||
| 1aa55984d6 | |||
| 38160d1fa1 | |||
| 2e40d45f04 | |||
| 3cc1bee2c0 | |||
| 35476eb8ef | |||
| 069e098cf0 | |||
| b3edb2aed1 | |||
| f3d3c0ebb5 | |||
| 4fe7a9787d | |||
| cb29f54a28 | |||
| 4cf9f6bee0 | |||
| db9aac2bf6 | |||
| b9ec452e72 | |||
| 45248acd74 | |||
| 5b3b2ac88d | |||
| f7a4494b39 | |||
| 06b7fc165c | |||
| a214a604e1 | |||
| 132d7e034f | |||
| ffba40650e | |||
| 20c12724fd | |||
| 8b2b5180ed | |||
| a7e9996441 | |||
| 026def2fde | |||
| 76085f14b0 | |||
| a927a6d4b3 | |||
| 876309e85c | |||
| 04e540a89d | |||
| 1051324b56 | |||
| cb546ee5e3 | |||
| c76341af0d | |||
| a00db24ebd | |||
| 5c41d80cae | |||
| 9149d3f0b5 | |||
| 77cdc67e97 | |||
| 824ddd8956 | |||
| 83cd49c753 | |||
| ab0a21244d | |||
| 68b87d181a | |||
| 7cd0aa234d | |||
| 40202d4793 | |||
| 4fcfe6fd7c | |||
| 3c7b2d5f79 | |||
| 8e5f4916c2 | |||
| d689834070 | |||
| fe8b3ea270 | |||
| cacc8ead4a | |||
| 99f409c8be | |||
| b3bdb0f75a | |||
| 92c80e3b87 | |||
| 589127b7df | |||
| 174e615ed9 | |||
| 20e08432b8 | |||
| a28fb19845 | |||
| d28f9e353a | |||
| d120ec8dc2 | |||
| a2a4bcf451 | |||
| b6e085e378 | |||
| 268ed47589 | |||
| 03cca64a48 | |||
| e38df0b7e0 | |||
| bf63b790f1 | |||
| 358b537cef |
4
.gitignore
vendored
|
|
@ -27,4 +27,6 @@ Thumbs.db
|
||||||
*.lnk
|
*.lnk
|
||||||
|
|
||||||
# How to setup Configuration Manager
|
# How to setup Configuration Manager
|
||||||
CONFIGURATION-MANAGER-HOWTO.md
|
CONFIGURATION-MANAGER-HOWTO.md
|
||||||
|
# Written by scripts/publish.* on a Release build from the root README; never edit or commit it.
|
||||||
|
/JotunnModStub/Package/README.md
|
||||||
|
|
|
||||||
|
|
@ -119,7 +119,10 @@ namespace RacesOfValheim
|
||||||
if (Time.time >= nextPulse)
|
if (Time.time >= nextPulse)
|
||||||
{
|
{
|
||||||
nextPulse = Time.time + AlfarPowerConfig.ArchonPulseInterval.Value;
|
nextPulse = Time.time + AlfarPowerConfig.ArchonPulseInterval.Value;
|
||||||
AlfarPowers.Pulse(player, AlfarPowerConfig.ArchonPulseRadius.Value, AlfarPowerConfig.ArchonPulseDamage.Value);
|
// The pulse fires on its own while the form lasts, so it earns what an aura does:
|
||||||
|
// a tenth of a hit per second, once per pulse that struck something.
|
||||||
|
if (AlfarPowers.Pulse(player, AlfarPowerConfig.ArchonPulseRadius.Value, AlfarPowerConfig.ArchonPulseDamage.Value))
|
||||||
|
FormMelee.RaiseSkill(Skills.SkillType.ElementalMagic, 0.1f * AlfarPowerConfig.ArchonPulseInterval.Value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
79
JotunnModStub/Alfar/AlfarChestGlow.cs
Normal file
|
|
@ -0,0 +1,79 @@
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace RacesOfValheim
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The light on the two Alfar chests, which says whether the drones have work there: the fire
|
||||||
|
/// chest's grate burns while it holds wood they may burn, the entry chest's inlay shines while it
|
||||||
|
/// holds anything but the sigil. Every client asks its own copy of the inventory, which Container
|
||||||
|
/// keeps in step with the ZDO, so nothing travels over the network for it.
|
||||||
|
/// </summary>
|
||||||
|
public class AlfarChestGlow : MonoBehaviour
|
||||||
|
{
|
||||||
|
public Renderer[] Glows;
|
||||||
|
public ParticleSystem Embers;
|
||||||
|
public Color GlowColor;
|
||||||
|
public bool WoodOnly;
|
||||||
|
|
||||||
|
private Container m_container;
|
||||||
|
private Material m_lit;
|
||||||
|
private Material m_cold;
|
||||||
|
private bool? m_shown;
|
||||||
|
private float m_nextCheck;
|
||||||
|
|
||||||
|
private void Awake()
|
||||||
|
{
|
||||||
|
m_container = GetComponent<Container>();
|
||||||
|
if (Glows == null || Glows.Length == 0 || Glows[0] == null) return;
|
||||||
|
|
||||||
|
m_cold = Glows[0].sharedMaterial;
|
||||||
|
m_lit = new Material(m_cold) { name = m_cold.name + "_lit" };
|
||||||
|
m_lit.color = Color.black;
|
||||||
|
m_lit.EnableKeyword("_EMISSION");
|
||||||
|
m_lit.SetColor("_EmissionColor", GlowColor);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Update()
|
||||||
|
{
|
||||||
|
if (Time.time < m_nextCheck) return;
|
||||||
|
m_nextCheck = Time.time + 1f;
|
||||||
|
|
||||||
|
bool lit = HasWork();
|
||||||
|
if (m_shown == lit) return;
|
||||||
|
m_shown = lit;
|
||||||
|
|
||||||
|
if (m_lit != null)
|
||||||
|
{
|
||||||
|
foreach (Renderer glow in Glows)
|
||||||
|
{
|
||||||
|
if (glow != null) glow.sharedMaterial = lit ? m_lit : m_cold;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (Embers != null)
|
||||||
|
{
|
||||||
|
if (lit) Embers.Play(true);
|
||||||
|
else Embers.Stop(true, ParticleSystemStopBehavior.StopEmitting);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool HasWork()
|
||||||
|
{
|
||||||
|
Inventory inventory = m_container != null ? m_container.GetInventory() : null;
|
||||||
|
if (inventory == null) return false;
|
||||||
|
|
||||||
|
foreach (ItemDrop.ItemData item in inventory.GetAllItems())
|
||||||
|
{
|
||||||
|
if (item == null || item.m_dropPrefab == null) continue;
|
||||||
|
|
||||||
|
string name = item.m_dropPrefab.name;
|
||||||
|
if (WoodOnly ? AlfarDroneAI.IsWood(name) : name != AlfarSigil.PrefabName) return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnDestroy()
|
||||||
|
{
|
||||||
|
if (m_lit != null) Destroy(m_lit);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -61,12 +61,15 @@ namespace RacesOfValheim
|
||||||
public static void Register()
|
public static void Register()
|
||||||
{
|
{
|
||||||
RegisterOne(EntryName, "$rov_piece_alfar_inngangskista_name", "$rov_piece_alfar_inngangskista_desc",
|
RegisterOne(EntryName, "$rov_piece_alfar_inngangskista_name", "$rov_piece_alfar_inngangskista_desc",
|
||||||
new Color(0.62f, 0.80f, 1f, 1f));
|
"$rov_hover_alfar_inngangskista", new Color(0.62f, 0.80f, 1f, 1f),
|
||||||
|
AlfarInputChest.Build, "AlfarInputChest_icon.png");
|
||||||
RegisterOne(WoodName, "$rov_piece_alfar_eldividarkista_name", "$rov_piece_alfar_eldividarkista_desc",
|
RegisterOne(WoodName, "$rov_piece_alfar_eldividarkista_name", "$rov_piece_alfar_eldividarkista_desc",
|
||||||
new Color(0.85f, 0.62f, 0.36f, 1f));
|
"$rov_hover_alfar_eldividarkista", new Color(0.85f, 0.62f, 0.36f, 1f),
|
||||||
|
AlfarFireChest.Build, "AlfarFireChest_icon.png");
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void RegisterOne(string pieceName, string display, string description, Color tint)
|
private static void RegisterOne(string pieceName, string display, string description, string hoverName, Color tint,
|
||||||
|
System.Func<GameObject, bool> build, string iconResource)
|
||||||
{
|
{
|
||||||
GameObject source = PrefabManager.Cache.GetPrefab<GameObject>("piece_chest_wood");
|
GameObject source = PrefabManager.Cache.GetPrefab<GameObject>("piece_chest_wood");
|
||||||
if (source == null)
|
if (source == null)
|
||||||
|
|
@ -91,15 +94,19 @@ namespace RacesOfValheim
|
||||||
}
|
}
|
||||||
requirements.Add(new RequirementConfig("GreydwarfEye", AlfarNexusConfig.ChestEyes.Value, 0, true));
|
requirements.Add(new RequirementConfig("GreydwarfEye", AlfarNexusConfig.ChestEyes.Value, 0, true));
|
||||||
|
|
||||||
|
// The hover and the chest window say what the chest is for, not only its name.
|
||||||
Container container = prefab.GetComponent<Container>();
|
Container container = prefab.GetComponent<Container>();
|
||||||
if (container != null) container.m_name = display;
|
if (container != null) container.m_name = hoverName;
|
||||||
|
|
||||||
Piece piece = prefab.GetComponent<Piece>();
|
Piece piece = prefab.GetComponent<Piece>();
|
||||||
if (piece == null) { Jotunn.Logger.LogWarning("[Alfar] The chest has no Piece: " + pieceName); return; }
|
if (piece == null) { Jotunn.Logger.LogWarning("[Alfar] The chest has no Piece: " + pieceName); return; }
|
||||||
piece.m_name = display;
|
piece.m_name = display;
|
||||||
piece.m_description = description;
|
piece.m_description = description;
|
||||||
|
|
||||||
AlfarConstructs.Tint(prefab, tint);
|
// Each chest has a body of its own; the tint stays as the fallback if it cannot be built.
|
||||||
|
Sprite icon = piece.m_icon;
|
||||||
|
if (!build(prefab)) AlfarConstructs.Tint(prefab, tint);
|
||||||
|
else icon = IconFrom(iconResource) ?? icon;
|
||||||
|
|
||||||
PieceManager.Instance.AddPiece(new CustomPiece(prefab, fixReference: false, new PieceConfig
|
PieceManager.Instance.AddPiece(new CustomPiece(prefab, fixReference: false, new PieceConfig
|
||||||
{
|
{
|
||||||
|
|
@ -107,7 +114,7 @@ namespace RacesOfValheim
|
||||||
Description = description,
|
Description = description,
|
||||||
PieceTable = PieceTables.Hammer,
|
PieceTable = PieceTables.Hammer,
|
||||||
Category = PieceCategories.Crafting,
|
Category = PieceCategories.Crafting,
|
||||||
Icon = piece.m_icon,
|
Icon = icon,
|
||||||
Requirements = requirements.ToArray(),
|
Requirements = requirements.ToArray(),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
|
@ -130,5 +137,12 @@ namespace RacesOfValheim
|
||||||
|
|
||||||
AlfarPieces.Extra.Add(pieceName);
|
AlfarPieces.Extra.Add(pieceName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal static Sprite IconFrom(string resource)
|
||||||
|
{
|
||||||
|
Texture2D texture = PieceLook.LoadTexture(resource);
|
||||||
|
if (texture == null) return null;
|
||||||
|
return Sprite.Create(texture, new Rect(0f, 0f, texture.width, texture.height), new Vector2(0.5f, 0.5f));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -39,17 +39,26 @@ namespace RacesOfValheim
|
||||||
public static ConfigEntry<float> WidthScale;
|
public static ConfigEntry<float> WidthScale;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 1 is the Sverm's size, which is what the design asked to try first ("se non va li
|
/// Scales the almond eyes (EyeExtent). The default 0.8 is the tuned grey look; raise it for
|
||||||
/// allarghiamo"). Raise it to enlarge the eyes: 1.6 is roughly a grey from the films.
|
/// bigger eyes.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static ConfigEntry<float> EyeSizeMultiplier;
|
public static ConfigEntry<float> EyeSizeMultiplier;
|
||||||
|
|
||||||
// The eye geometry is the Sverm's, unchanged (SvermVisuals): offsets are metres in the head
|
// A grey's eyes, on the Sverm's eye spot: offsets are metres in the head bone's OWN frame
|
||||||
// bone's OWN frame, so they land on the same part of the face at any body scale.
|
// at human scale, so they land on the same part of the face at any body scale.
|
||||||
public const float EyeSeparation = 0.032f;
|
// Pushed apart and forward of the Sverm's, because an almond this wide would otherwise
|
||||||
public const float EyeForward = 0.081f;
|
// meet its twin over the nose and sink into the cheek.
|
||||||
public const float EyeHeight = 0.181f;
|
public const float EyeSeparation = 0.037f;
|
||||||
public const float EyeSize = 0.062f;
|
public const float EyeForward = 0.090f;
|
||||||
|
public const float EyeHeight = 0.183f;
|
||||||
|
|
||||||
|
// Full width, height and depth of one eye in metres at Eye Size Multiplier 1. The saved
|
||||||
|
// default of 0.8 makes that 50 x 28 x 18 mm.
|
||||||
|
public static readonly Vector3 EyeExtent = new Vector3(0.0625f, 0.035f, 0.0225f);
|
||||||
|
|
||||||
|
// Degrees. Slant raises the outer corner; wrap turns each eye out toward its temple.
|
||||||
|
public const float EyeSlant = 22f;
|
||||||
|
public const float EyeWrap = 20f;
|
||||||
|
|
||||||
// ─── Eitr: diet, shield, soft fall ───────────────────────────────────
|
// ─── Eitr: diet, shield, soft fall ───────────────────────────────────
|
||||||
|
|
||||||
|
|
@ -152,7 +161,7 @@ namespace RacesOfValheim
|
||||||
new AcceptableValueRange<float>(0.7f, 1.2f)));
|
new AcceptableValueRange<float>(0.7f, 1.2f)));
|
||||||
|
|
||||||
EyeSizeMultiplier = config.Bind(look, "Eye Size Multiplier", 0.8f,
|
EyeSizeMultiplier = config.Bind(look, "Eye Size Multiplier", 0.8f,
|
||||||
new ConfigDescription("1 = the Sverm's eye size; 0.8 is slightly smaller. Raise to enlarge the black eyes.",
|
new ConfigDescription("Scales the black almond eyes. 0.8 is the default look; raise it for bigger eyes.",
|
||||||
new AcceptableValueRange<float>(0.5f, 3f)));
|
new AcceptableValueRange<float>(0.5f, 3f)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -58,6 +58,13 @@ namespace RacesOfValheim
|
||||||
public const string KeyStatus = "RoV_alfarStatus";
|
public const string KeyStatus = "RoV_alfarStatus";
|
||||||
public const string KeyDest = "RoV_alfarDest";
|
public const string KeyDest = "RoV_alfarDest";
|
||||||
|
|
||||||
|
// What the drone last said: a counter every client watches, the text key and the item.
|
||||||
|
// Each client builds the line in its own language, so only the token travels.
|
||||||
|
public const string KeySaySeq = "RoV_alfarSaySeq";
|
||||||
|
public const string KeySayKey = "RoV_alfarSayKey";
|
||||||
|
public const string KeySayItem = "RoV_alfarSayItem";
|
||||||
|
public const string KeySayStation = "RoV_alfarSayStation";
|
||||||
|
|
||||||
/// <summary>Every drone alive in the loaded zones: the repairs look at each other through it.</summary>
|
/// <summary>Every drone alive in the loaded zones: the repairs look at each other through it.</summary>
|
||||||
public static readonly List<AlfarDroneAI> All = new List<AlfarDroneAI>();
|
public static readonly List<AlfarDroneAI> All = new List<AlfarDroneAI>();
|
||||||
|
|
||||||
|
|
@ -141,6 +148,7 @@ namespace RacesOfValheim
|
||||||
|
|
||||||
private float m_nextFightScan;
|
private float m_nextFightScan;
|
||||||
private float m_fightUntil;
|
private float m_fightUntil;
|
||||||
|
private bool m_fighting;
|
||||||
|
|
||||||
private ZNetView m_nview;
|
private ZNetView m_nview;
|
||||||
private Character m_character;
|
private Character m_character;
|
||||||
|
|
@ -168,6 +176,11 @@ namespace RacesOfValheim
|
||||||
private ZDOID m_sortDest;
|
private ZDOID m_sortDest;
|
||||||
private float m_scannedAt = -99f;
|
private float m_scannedAt = -99f;
|
||||||
|
|
||||||
|
// Speech: the last line this client showed, and when to look for a new one.
|
||||||
|
private int m_heardSeq;
|
||||||
|
private float m_nextListen;
|
||||||
|
private float m_nextKilnCheck;
|
||||||
|
|
||||||
private Job m_job;
|
private Job m_job;
|
||||||
private float m_nextPlan;
|
private float m_nextPlan;
|
||||||
private float m_jobDeadline;
|
private float m_jobDeadline;
|
||||||
|
|
@ -200,6 +213,16 @@ namespace RacesOfValheim
|
||||||
|
|
||||||
All.Add(this);
|
All.Add(this);
|
||||||
ReadPayload();
|
ReadPayload();
|
||||||
|
|
||||||
|
// A line said before this object loaded is old news: do not replay it on a zone reload.
|
||||||
|
if (m_nview != null && m_nview.IsValid()) m_heardSeq = m_nview.GetZDO().GetInt(KeySaySeq, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Update()
|
||||||
|
{
|
||||||
|
if (Time.time < m_nextListen) return;
|
||||||
|
m_nextListen = Time.time + 0.5f;
|
||||||
|
Listen();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnDestroy()
|
private void OnDestroy()
|
||||||
|
|
@ -293,7 +316,17 @@ namespace RacesOfValheim
|
||||||
if (!m_fightsBack || m_ai == null || m_character == null || m_character.IsDead()) return false;
|
if (!m_fightsBack || m_ai == null || m_character == null || m_character.IsDead()) return false;
|
||||||
if (m_nview == null || !m_nview.IsValid() || !m_nview.IsOwner()) return false;
|
if (m_nview == null || !m_nview.IsValid() || !m_nview.IsOwner()) return false;
|
||||||
|
|
||||||
|
// A tamed MonsterAI with no patrol point and no follow target never drops its target for
|
||||||
|
// distance (UpdateTarget, IL): only after 30 s unsensed or 60 s without a swing. The drone
|
||||||
|
// hears far, so an enemy that ran off kept "being sensed" and held the tick for vanilla.
|
||||||
|
// Past the leash it is no longer this drone's fight.
|
||||||
Character target = m_ai.GetTargetCreature();
|
Character target = m_ai.GetTargetCreature();
|
||||||
|
if (target != null && !target.IsDead() && !InFightReach(target))
|
||||||
|
{
|
||||||
|
m_ai.MakeTame();
|
||||||
|
target = null;
|
||||||
|
}
|
||||||
|
|
||||||
if (target != null && !target.IsDead())
|
if (target != null && !target.IsDead())
|
||||||
{
|
{
|
||||||
m_fightUntil = Time.time + FightLinger;
|
m_fightUntil = Time.time + FightLinger;
|
||||||
|
|
@ -301,20 +334,43 @@ namespace RacesOfValheim
|
||||||
else if (Time.time >= m_nextFightScan)
|
else if (Time.time >= m_nextFightScan)
|
||||||
{
|
{
|
||||||
m_nextFightScan = Time.time + FightScanInterval;
|
m_nextFightScan = Time.time + FightScanInterval;
|
||||||
if (BaseAI.FindClosestEnemy(m_character, transform.position, FightRange) != null)
|
// FindClosestEnemy takes its first match at ANY distance (it only compares against
|
||||||
|
// maxDistance once it holds one), so with a deer anywhere in the loaded zones it never
|
||||||
|
// returned null and vanilla kept the tick: the drone idled about instead of working.
|
||||||
|
Character enemy = BaseAI.FindClosestEnemy(m_character, transform.position, FightRange);
|
||||||
|
if (enemy != null && Vector3.Distance(enemy.transform.position, transform.position) <= FightRange)
|
||||||
{
|
{
|
||||||
m_fightUntil = Time.time + FightLinger;
|
m_fightUntil = Time.time + FightLinger;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Time.time >= m_fightUntil) return false;
|
if (Time.time >= m_fightUntil)
|
||||||
|
{
|
||||||
|
// The fight is over: clear what vanilla still holds (target, alert), or the next
|
||||||
|
// GetTargetCreature hands the tick straight back to it. MakeTame is the public door
|
||||||
|
// that nulls both targets and the alert in one call; the drone is tamed already.
|
||||||
|
if (m_fighting) { m_fighting = false; m_ai.MakeTame(); }
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_fighting = true;
|
||||||
m_job = null;
|
m_job = null;
|
||||||
m_nextPlan = 0f; // the fight moved it; plan afresh the moment it hands back
|
m_nextPlan = 0f; // the fight moved it; plan afresh the moment it hands back
|
||||||
SetStatus("Fighting.");
|
SetStatus("Fighting.");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>Close to the drone, and not past the edge of the base it works.</summary>
|
||||||
|
private bool InFightReach(Character enemy)
|
||||||
|
{
|
||||||
|
Vector3 at = enemy.transform.position;
|
||||||
|
if (Vector3.Distance(at, transform.position) > FightRange * 2f) return false;
|
||||||
|
|
||||||
|
Vector3? anchor = Anchor;
|
||||||
|
float leash = AlfarNexusConfig.NexusRadius.Value + m_radiusBonus + FightRange;
|
||||||
|
return anchor == null || Vector3.Distance(at, anchor.Value) <= leash;
|
||||||
|
}
|
||||||
|
|
||||||
// ================================================================ the tick
|
// ================================================================ the tick
|
||||||
|
|
||||||
/// <summary>Everything. Returns what MonsterAI.UpdateAI would have returned.</summary>
|
/// <summary>Everything. Returns what MonsterAI.UpdateAI would have returned.</summary>
|
||||||
|
|
@ -389,17 +445,34 @@ namespace RacesOfValheim
|
||||||
|
|
||||||
Scan(anchor.Value);
|
Scan(anchor.Value);
|
||||||
ExpirePenalties();
|
ExpirePenalties();
|
||||||
|
CheckIdleKiln();
|
||||||
|
|
||||||
// A harvest is in progress: wait for the drops to land, then gather them and replant.
|
// A harvest is in progress: wait for the drops to land, then gather them and replant.
|
||||||
|
Job job;
|
||||||
if (m_farmSpot != null)
|
if (m_farmSpot != null)
|
||||||
{
|
{
|
||||||
m_job = Time.time < m_farmReadyAt
|
job = Time.time < m_farmReadyAt
|
||||||
? new Job { Kind = "wait", Point = transform.position, Label = "Waiting" }
|
? new Job { Kind = "wait", Point = transform.position, Label = "Waiting" }
|
||||||
: new Job { Kind = "farm_finish", Point = m_farmSpot.Value, Label = "Gathering" };
|
: new Job { Kind = "farm_finish", Point = m_farmSpot.Value, Label = "Gathering" };
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
// A delivery is a job like any other and gets its own clock. It used to return early here
|
||||||
|
// and inherit the load's deadline: a slow trip, or a fight on the way, left it already late,
|
||||||
|
// so it timed out on the first tick, was planned again, timed out again, every frame - the
|
||||||
|
// drone froze with wood in hand next to the kiln (10790 timeouts in one player's log).
|
||||||
|
else if (m_payload.Count > 0) job = PlanDelivery(anchor.Value);
|
||||||
|
else job = PlanWork(anchor.Value);
|
||||||
|
|
||||||
if (m_payload.Count > 0) { m_job = PlanDelivery(anchor.Value); return; }
|
if (job != null && (m_job == null || m_job.Kind != job.Kind || m_job.Target != job.Target))
|
||||||
|
{
|
||||||
|
m_jobDeadline = Time.time + JobTimeout;
|
||||||
|
}
|
||||||
|
if (m_job != null && !ReferenceEquals(m_job, job)) Release(m_job.Claim);
|
||||||
|
if (job != null) Claim(job.Claim);
|
||||||
|
m_job = job;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Job PlanWork(Vector3 anchor)
|
||||||
|
{
|
||||||
|
|
||||||
// The forge has no clock: a smelter holds its ore indefinitely and puts its own output on
|
// The forge has no clock: a smelter holds its ore indefinitely and puts its own output on
|
||||||
// the floor, so PlanRescue would ask a question whose answer is always no. The smith is a
|
// the floor, so PlanRescue would ask a question whose answer is always no. The smith is a
|
||||||
|
|
@ -415,15 +488,7 @@ namespace RacesOfValheim
|
||||||
// base: repairs, the fields, and last the tidying of the entry chest.
|
// base: repairs, the fields, and last the tidying of the entry chest.
|
||||||
Job job = PlanRescue();
|
Job job = PlanRescue();
|
||||||
job = job ?? PlanCollect() ?? PlanFuel() ?? PlanLoad();
|
job = job ?? PlanCollect() ?? PlanFuel() ?? PlanLoad();
|
||||||
job = job ?? PlanRepair(anchor.Value) ?? PlanFarm(anchor.Value) ?? PlanSort();
|
return job ?? PlanRepair(anchor) ?? PlanFarm(anchor) ?? PlanSort();
|
||||||
|
|
||||||
if (job != null && (m_job == null || m_job.Kind != job.Kind || m_job.Target != job.Target))
|
|
||||||
{
|
|
||||||
m_jobDeadline = Time.time + JobTimeout;
|
|
||||||
}
|
|
||||||
if (m_job != null && !ReferenceEquals(m_job, job)) Release(m_job.Claim);
|
|
||||||
if (job != null) Claim(job.Claim);
|
|
||||||
m_job = job;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -552,7 +617,7 @@ namespace RacesOfValheim
|
||||||
Kind = "collect",
|
Kind = "collect",
|
||||||
Target = best.Id,
|
Target = best.Id,
|
||||||
Claim = best.Id,
|
Claim = best.Id,
|
||||||
Point = best.Position,
|
Point = ApproachPoint(best),
|
||||||
Hurry = true,
|
Hurry = true,
|
||||||
Label = "Saving the food",
|
Label = "Saving the food",
|
||||||
};
|
};
|
||||||
|
|
@ -583,7 +648,7 @@ namespace RacesOfValheim
|
||||||
Kind = "collect",
|
Kind = "collect",
|
||||||
Target = best.Id,
|
Target = best.Id,
|
||||||
Claim = best.Id,
|
Claim = best.Id,
|
||||||
Point = best.Position,
|
Point = ApproachPoint(best),
|
||||||
Label = "Collecting",
|
Label = "Collecting",
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
@ -713,20 +778,37 @@ namespace RacesOfValheim
|
||||||
// coal, so gating the delivery on free slots sent the servant back to the chest with
|
// coal, so gating the delivery on free slots sent the servant back to the chest with
|
||||||
// the coal it had just fetched - and then PlanFuel sent it out for the same coal again,
|
// the coal it had just fetched - and then PlanFuel sent it out for the same coal again,
|
||||||
// forever. AcceptsAnything already asks the right question of both doors.
|
// forever. AcceptsAnything already asks the right question of both doors.
|
||||||
|
// A station it could not reach is in the penalty box: asking it again straight away
|
||||||
|
// is the same failed trip.
|
||||||
|
bool unreachable = IsPenalised(target);
|
||||||
ButlerStation station = StationById(target);
|
ButlerStation station = StationById(target);
|
||||||
if (station != null && station.Alive && station.Operable && AcceptsAnything(station))
|
if (station != null && station.Alive && station.Operable && AcceptsAnything(station) && !unreachable)
|
||||||
{
|
{
|
||||||
return new Job
|
return new Job
|
||||||
{
|
{
|
||||||
Kind = "deposit_station",
|
Kind = "deposit_station",
|
||||||
Target = target,
|
Target = target,
|
||||||
Point = station.Position,
|
Point = ApproachPoint(station),
|
||||||
Label = "Loading " + Describe(),
|
Label = "Loading " + Describe(),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
// The station is gone, full or cold. The goods are ours to put back, not to hold.
|
// The station is gone, full or cold. The goods are ours to put back, not to hold.
|
||||||
m_nview.GetZDO().Set(KeyTarget, ZDOID.None);
|
m_nview.GetZDO().Set(KeyTarget, ZDOID.None);
|
||||||
|
|
||||||
|
// Out of reach, the load goes back where it came from: the Eldividarkista's wood stays
|
||||||
|
// fuel instead of landing in the entry chest and being sorted away into storage.
|
||||||
|
Container source = unreachable ? ContainerById(m_nview.GetZDO().GetZDOID(KeySource)) : null;
|
||||||
|
if (source != null && !IsMarkedOff(source) && !IsPenalised(ZdoOf(source)) && HasRoomFor(source))
|
||||||
|
{
|
||||||
|
return new Job
|
||||||
|
{
|
||||||
|
Kind = "deposit",
|
||||||
|
Target = ZdoOf(source),
|
||||||
|
Point = source.transform.position,
|
||||||
|
Label = "Storing " + Describe(),
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Container chest = ChestForProduct();
|
Container chest = ChestForProduct();
|
||||||
|
|
@ -759,7 +841,7 @@ namespace RacesOfValheim
|
||||||
{
|
{
|
||||||
Kind = "deposit_station",
|
Kind = "deposit_station",
|
||||||
Target = consumer.Id,
|
Target = consumer.Id,
|
||||||
Point = consumer.Position,
|
Point = ApproachPoint(consumer),
|
||||||
Label = "Loading " + Describe(),
|
Label = "Loading " + Describe(),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
@ -1418,16 +1500,25 @@ namespace RacesOfValheim
|
||||||
if (inventory == null) return null;
|
if (inventory == null) return null;
|
||||||
|
|
||||||
string sigil = AlfarSigil.PrefabName;
|
string sigil = AlfarSigil.PrefabName;
|
||||||
|
bool spoke = false;
|
||||||
foreach (ItemDrop.ItemData item in inventory.GetAllItems())
|
foreach (ItemDrop.ItemData item in inventory.GetAllItems())
|
||||||
{
|
{
|
||||||
if (item == null || item.m_dropPrefab == null) continue;
|
if (item == null || item.m_dropPrefab == null) continue;
|
||||||
|
|
||||||
string name = item.m_dropPrefab.name;
|
string name = item.m_dropPrefab.name;
|
||||||
if (name == sigil) continue;
|
if (name == sigil) continue;
|
||||||
if (!IsWood(name) && AnyStationAccepts(name)) continue;
|
if (!IsWood(name) && AnyStationAccepts(name))
|
||||||
|
{
|
||||||
|
if (!spoke) spoke = Say("rov_msg_alfar_drone_sort_keep", name, KeepRepeatSeconds);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
Container destination = DestinationFor(name);
|
Container destination = DestinationFor(name);
|
||||||
if (destination == null) continue;
|
if (destination == null)
|
||||||
|
{
|
||||||
|
if (!spoke) spoke = Say("rov_msg_alfar_drone_sort_nowhere", name, NowhereRepeatSeconds);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
m_sortItem = name;
|
m_sortItem = name;
|
||||||
m_sortDest = ZdoOf(destination);
|
m_sortDest = ZdoOf(destination);
|
||||||
|
|
@ -1443,6 +1534,119 @@ namespace RacesOfValheim
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ================================================================ speech
|
||||||
|
|
||||||
|
/// <summary>When each item may be mentioned again, shared by every drone on this client, so
|
||||||
|
/// five drones looking at the same stone say it once and not five times.</summary>
|
||||||
|
private static readonly Dictionary<string, float> s_nextMention = new Dictionary<string, float>();
|
||||||
|
private const float NowhereRepeatSeconds = 300f;
|
||||||
|
private const float KeepRepeatSeconds = 1800f;
|
||||||
|
private const float SpeechRange = 40f;
|
||||||
|
|
||||||
|
/// <summary>Owner side: says the line once per cooldown per item, by writing it into the ZDO
|
||||||
|
/// where every client in range picks it up. Returns whether it spoke, so one plan says one
|
||||||
|
/// line and the bubbles do not overwrite each other.</summary>
|
||||||
|
private bool Say(string key, string item, float repeatSeconds, string station = "")
|
||||||
|
{
|
||||||
|
string mention = key + "|" + item;
|
||||||
|
float next;
|
||||||
|
if (s_nextMention.TryGetValue(mention, out next) && Time.time < next) return false;
|
||||||
|
s_nextMention[mention] = Time.time + repeatSeconds;
|
||||||
|
|
||||||
|
ZDO zdo = m_nview.GetZDO();
|
||||||
|
zdo.Set(KeySayKey, key);
|
||||||
|
zdo.Set(KeySayItem, item);
|
||||||
|
zdo.Set(KeySayStation, station);
|
||||||
|
zdo.Set(KeySaySeq, zdo.GetInt(KeySaySeq, 0) + 1);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>Every client: a new line in the ZDO goes over the drone's head, the way vanilla's
|
||||||
|
/// NPCs talk, and into the chat window, for players close enough to care.</summary>
|
||||||
|
private void Listen()
|
||||||
|
{
|
||||||
|
if (m_nview == null || !m_nview.IsValid()) return;
|
||||||
|
|
||||||
|
ZDO zdo = m_nview.GetZDO();
|
||||||
|
int seq = zdo.GetInt(KeySaySeq, 0);
|
||||||
|
if (seq == m_heardSeq) return;
|
||||||
|
m_heardSeq = seq;
|
||||||
|
|
||||||
|
Player player = Player.m_localPlayer;
|
||||||
|
if (player == null || Chat.instance == null) return;
|
||||||
|
if (Vector3.Distance(player.transform.position, transform.position) > SpeechRange) return;
|
||||||
|
|
||||||
|
string item = zdo.GetString(KeySayItem, "");
|
||||||
|
GameObject prefab = ObjectDB.instance != null ? ObjectDB.instance.GetItemPrefab(item) : null;
|
||||||
|
ItemDrop drop = prefab != null ? prefab.GetComponent<ItemDrop>() : null;
|
||||||
|
string itemName = drop != null ? drop.m_itemData.m_shared.m_name : item;
|
||||||
|
|
||||||
|
string text = ModText.Get(zdo.GetString(KeySayKey, ""), itemName,
|
||||||
|
"$rov_piece_alfar_inngangskista_name", "$rov_piece_alfar_eldividarkista_name",
|
||||||
|
zdo.GetString(KeySayStation, ""));
|
||||||
|
string speaker = m_character != null ? Localization.instance.Localize(m_character.m_name) : "";
|
||||||
|
|
||||||
|
Chat.instance.SetNpcText(gameObject, Vector3.up * 1.5f, SpeechRange, 8f, speaker, text, false);
|
||||||
|
Chat.instance.AddString(speaker, text, Talker.Type.Normal);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The mistake players make with the kiln: the wood is in a plain chest (vanilla even calls
|
||||||
|
/// one "Wood chest"), and only the Eldividarkista's wood is ever burnt. A station that takes
|
||||||
|
/// wood, standing idle with nothing for it in the Eldividarkista while the right wood sits in
|
||||||
|
/// another chest, gets a line explaining that. Every 30 s is plenty for something the player
|
||||||
|
/// fixes by hand.
|
||||||
|
/// </summary>
|
||||||
|
private void CheckIdleKiln()
|
||||||
|
{
|
||||||
|
if (Time.time < m_nextKilnCheck) return;
|
||||||
|
m_nextKilnCheck = Time.time + 30f;
|
||||||
|
|
||||||
|
foreach (ButlerStation station in m_stations)
|
||||||
|
{
|
||||||
|
if (!station.Alive || !station.Operable || station.HasWork || station.FreeSlots <= 0) continue;
|
||||||
|
if (m_wood != null && FirstAccepted(station, m_wood) != null) continue;
|
||||||
|
|
||||||
|
string misplaced = WoodElsewhereFor(station);
|
||||||
|
if (misplaced == null) continue;
|
||||||
|
|
||||||
|
// The station's own name token, so every language says "kiln" the game's way.
|
||||||
|
Piece piece = station.Behaviour.GetComponent<Piece>();
|
||||||
|
string stationName = piece != null ? piece.m_name : "";
|
||||||
|
if (Say("rov_msg_alfar_drone_kiln_wood", misplaced, NowhereRepeatSeconds, stationName)) return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>Wood the station would take, lying in the entry chest or a storage chest.</summary>
|
||||||
|
private string WoodElsewhereFor(ButlerStation station)
|
||||||
|
{
|
||||||
|
if (m_entry != null)
|
||||||
|
{
|
||||||
|
string found = WoodIn(m_entry, station);
|
||||||
|
if (found != null) return found;
|
||||||
|
}
|
||||||
|
foreach (Container chest in m_chests)
|
||||||
|
{
|
||||||
|
string found = WoodIn(chest, station);
|
||||||
|
if (found != null) return found;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static string WoodIn(Container chest, ButlerStation station)
|
||||||
|
{
|
||||||
|
Inventory inventory = chest != null ? chest.GetInventory() : null;
|
||||||
|
if (inventory == null) return null;
|
||||||
|
|
||||||
|
foreach (ItemDrop.ItemData item in inventory.GetAllItems())
|
||||||
|
{
|
||||||
|
if (item == null || item.m_dropPrefab == null) continue;
|
||||||
|
string name = item.m_dropPrefab.name;
|
||||||
|
if (IsWood(name) && station.Accepts(name)) return name;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
private bool DoSortFetch()
|
private bool DoSortFetch()
|
||||||
{
|
{
|
||||||
if (m_sortItem == null || m_sortDest == ZDOID.None) return false;
|
if (m_sortItem == null || m_sortDest == ZDOID.None) return false;
|
||||||
|
|
@ -1463,6 +1667,169 @@ namespace RacesOfValheim
|
||||||
// ================================================================ moving
|
// ================================================================ moving
|
||||||
|
|
||||||
/// <summary>Vanilla pathing, through the private MoveTo. True the moment it has arrived.</summary>
|
/// <summary>Vanilla pathing, through the private MoveTo. True the moment it has arrived.</summary>
|
||||||
|
/// <summary>F8 readout: what each worker within 60 m is doing and what vanilla still holds, and
|
||||||
|
/// for the nearest one, why each thing in the entry chest is (or is not) being sorted.</summary>
|
||||||
|
public static void DebugReport(Player player)
|
||||||
|
{
|
||||||
|
var lines = new List<string>();
|
||||||
|
AlfarDroneAI nearest = null;
|
||||||
|
float nearestDistance = 60f;
|
||||||
|
|
||||||
|
foreach (AlfarDroneAI drone in All)
|
||||||
|
{
|
||||||
|
if (drone == null || drone.m_ai == null) continue;
|
||||||
|
float distance = Vector3.Distance(drone.transform.position, player.transform.position);
|
||||||
|
if (distance > 60f) continue;
|
||||||
|
if (distance < nearestDistance) { nearestDistance = distance; nearest = drone; }
|
||||||
|
|
||||||
|
Character target = drone.m_ai.GetTargetCreature();
|
||||||
|
string targetText = target != null
|
||||||
|
? $"{Utils.GetPrefabName(target.gameObject)} {Vector3.Distance(target.transform.position, drone.transform.position):0}m"
|
||||||
|
: "none";
|
||||||
|
lines.Add($"[RoV drone] {distance:0}m: '{drone.Status}' job {(drone.m_job != null ? drone.m_job.Kind : "none")} " +
|
||||||
|
$"carry {drone.PayloadCount()} fight {drone.m_fighting} vanilla target {targetText} " +
|
||||||
|
$"alerted {drone.m_ai.IsAlerted()} flying {drone.m_character.IsFlying()} owner {drone.m_nview.IsOwner()}");
|
||||||
|
|
||||||
|
// The other half of what holds a fight: the 12 m sweep, and how long the linger has left.
|
||||||
|
Character near = BaseAI.FindClosestEnemy(drone.m_character, drone.transform.position, FightRange);
|
||||||
|
string nearText = near != null
|
||||||
|
? $"{Utils.GetPrefabName(near.gameObject)} {Vector3.Distance(near.transform.position, drone.transform.position):0}m"
|
||||||
|
: "none";
|
||||||
|
lines.Add($"[RoV drone] fight left {Mathf.Max(0f, drone.m_fightUntil - Time.time):0.0}s, " +
|
||||||
|
$"closest enemy {nearText}, in reach {(target != null && drone.InFightReach(target))}");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (nearest == null) lines.Add("[RoV drone] no worker drone within 60m");
|
||||||
|
else
|
||||||
|
{
|
||||||
|
lines.AddRange(nearest.SortReport());
|
||||||
|
lines.AddRange(nearest.StationReport());
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (string line in lines)
|
||||||
|
{
|
||||||
|
Debug.Log(line);
|
||||||
|
player.Message(MessageHud.MessageType.TopLeft, line);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>Why a station is (or is not) fed: what the last scan saw, the wood chest, and every
|
||||||
|
/// smelter, hearth or fermenter within the radius - and the ones just past it, by how much.</summary>
|
||||||
|
private IEnumerable<string> StationReport()
|
||||||
|
{
|
||||||
|
Vector3? anchor = Anchor;
|
||||||
|
if (anchor == null) { yield return "[RoV station] no anchor"; yield break; }
|
||||||
|
|
||||||
|
float radius = AlfarNexusConfig.NexusRadius.Value + m_radiusBonus;
|
||||||
|
yield return $"[RoV station] anchor {Vector3.Distance(transform.position, anchor.Value):0}m from drone, " +
|
||||||
|
$"radius {radius:0}, scanned {Time.time - m_scannedAt:0}s ago, {m_stations.Count} stations, {m_chests.Count} chests";
|
||||||
|
|
||||||
|
if (m_wood == null) yield return "[RoV station] no Eldividarkista in range (or it is open, or holds the sigil)";
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var wood = new List<string>();
|
||||||
|
Inventory inventory = m_wood.GetInventory();
|
||||||
|
if (inventory != null)
|
||||||
|
{
|
||||||
|
foreach (ItemDrop.ItemData item in inventory.GetAllItems())
|
||||||
|
{
|
||||||
|
wood.Add(item.m_dropPrefab != null ? $"{item.m_dropPrefab.name}x{item.m_stack}" : $"{item.m_shared.m_name}(no prefab)");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
yield return $"[RoV station] Eldividarkista {Vector3.Distance(m_wood.transform.position, anchor.Value):0}m from anchor, " +
|
||||||
|
$"open {m_wood.IsInUse()}, penalty {IsPenalised(ZdoOf(m_wood))}, holds [{string.Join(", ", wood.ToArray())}]";
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (ButlerStation station in m_stations)
|
||||||
|
{
|
||||||
|
if (!station.Alive) { yield return "[RoV station] (a station that is gone)"; continue; }
|
||||||
|
|
||||||
|
Container chest;
|
||||||
|
string material = FindMaterialFor(station, out chest);
|
||||||
|
string from = material == null ? "nothing" : $"{material} from {(chest == m_wood ? "Eldividarkista" : "entry")}";
|
||||||
|
yield return $"[RoV station] {Utils.GetPrefabName(station.Behaviour.gameObject)} " +
|
||||||
|
$"{Vector3.Distance(station.Position, anchor.Value):0}m: operable {station.Operable} free {station.FreeSlots} " +
|
||||||
|
$"work {station.HasWork} wood {station.Accepts("Wood")} penalty {IsPenalised(station.Id)} " +
|
||||||
|
$"claimed {ClaimedByOther(station.Id)} fuel {station.FuelPrefab ?? "-"}/{station.FuelWanted} | load: {from}";
|
||||||
|
}
|
||||||
|
|
||||||
|
// A station the scan cannot see because it stands past the edge.
|
||||||
|
List<Piece> pieces = AllPiecesField != null ? AllPiecesField.GetValue(null) as List<Piece> : null;
|
||||||
|
if (pieces == null) yield break;
|
||||||
|
foreach (Piece piece in pieces)
|
||||||
|
{
|
||||||
|
if (piece == null) continue;
|
||||||
|
float distance = Vector3.Distance(piece.transform.position, anchor.Value);
|
||||||
|
if (distance <= radius || distance > radius + 15f) continue;
|
||||||
|
if (ButlerStation.From(piece.gameObject) == null) continue;
|
||||||
|
yield return $"[RoV station] {Utils.GetPrefabName(piece.gameObject)} {distance:0}m: OUTSIDE the radius by {distance - radius:0.0}m";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private IEnumerable<string> SortReport()
|
||||||
|
{
|
||||||
|
if (m_entry == null) { yield return "[RoV sort] no entry chest in range"; yield break; }
|
||||||
|
if (m_entry.IsInUse()) yield return "[RoV sort] entry chest is open";
|
||||||
|
if (IsPenalised(ZdoOf(m_entry))) yield return "[RoV sort] entry chest is set aside (penalty)";
|
||||||
|
|
||||||
|
Inventory inventory = m_entry.GetInventory();
|
||||||
|
if (inventory == null) yield break;
|
||||||
|
|
||||||
|
var seen = new HashSet<string>();
|
||||||
|
foreach (ItemDrop.ItemData item in inventory.GetAllItems())
|
||||||
|
{
|
||||||
|
if (item == null) continue;
|
||||||
|
if (item.m_dropPrefab == null) { yield return $"[RoV sort] {item.m_shared.m_name}: no drop prefab"; continue; }
|
||||||
|
|
||||||
|
string name = item.m_dropPrefab.name;
|
||||||
|
if (!seen.Add(name)) continue;
|
||||||
|
|
||||||
|
string verdict;
|
||||||
|
if (name == AlfarSigil.PrefabName) verdict = "sigil, stays";
|
||||||
|
else if (!IsWood(name) && AnyStationAccepts(name)) verdict = "a station takes it, stays as work";
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Container destination = DestinationFor(name);
|
||||||
|
verdict = destination != null
|
||||||
|
? $"goes to chest at {Vector3.Distance(destination.transform.position, m_entry.transform.position):0}m"
|
||||||
|
: $"nowhere: no storage chest holds it and none is empty ({m_chests.Count} chests)";
|
||||||
|
}
|
||||||
|
yield return $"[RoV sort] {name}: {verdict}";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Where the drone flies to serve a station: beside it, a metre past its colliders on the side
|
||||||
|
/// the drone comes from. Vanilla lifts a flyer's goal to m_flyAltitudeMin over the ground under
|
||||||
|
/// it (BaseAI.MoveTo, IL), and under a charcoal kiln's origin that is inside the dome: the drone
|
||||||
|
/// pressed against the stone, never came within ArriveDistance, and the kiln went into the
|
||||||
|
/// penalty box (snakey's log, "Could not reach collect target"). Beside it is open air, and it
|
||||||
|
/// stays under a roof indoors, where aiming over the top would not. The loading and the sweep
|
||||||
|
/// still work from the station's own position.
|
||||||
|
/// </summary>
|
||||||
|
private Vector3 ApproachPoint(ButlerStation station)
|
||||||
|
{
|
||||||
|
Vector3 centre = station.Position;
|
||||||
|
bool any = false;
|
||||||
|
Bounds bounds = new Bounds(centre, Vector3.zero);
|
||||||
|
foreach (Collider collider in station.Behaviour.GetComponentsInChildren<Collider>())
|
||||||
|
{
|
||||||
|
if (collider == null || !collider.enabled || collider.isTrigger) continue;
|
||||||
|
if (any) bounds.Encapsulate(collider.bounds);
|
||||||
|
else { bounds = collider.bounds; any = true; }
|
||||||
|
}
|
||||||
|
if (!any) return centre;
|
||||||
|
|
||||||
|
Vector3 away = transform.position - bounds.center;
|
||||||
|
away.y = 0f;
|
||||||
|
if (away.sqrMagnitude < 0.01f) away = station.Transform.forward;
|
||||||
|
float reach = Mathf.Max(bounds.extents.x, bounds.extents.z) + 1f;
|
||||||
|
|
||||||
|
Vector3 point = bounds.center + away.normalized * reach;
|
||||||
|
point.y = centre.y;
|
||||||
|
return point;
|
||||||
|
}
|
||||||
|
|
||||||
private bool MoveToPoint(float dt, Vector3 point, float distance, bool run)
|
private bool MoveToPoint(float dt, Vector3 point, float distance, bool run)
|
||||||
{
|
{
|
||||||
if (m_ai == null || MoveToMethod == null) return true; // cannot walk: act in place
|
if (m_ai == null || MoveToMethod == null) return true; // cannot walk: act in place
|
||||||
|
|
@ -1633,7 +2000,7 @@ namespace RacesOfValheim
|
||||||
"Wood", "FineWood", "RoundLog", "ElderBark", "YggdrasilWood", "Blackwood",
|
"Wood", "FineWood", "RoundLog", "ElderBark", "YggdrasilWood", "Blackwood",
|
||||||
};
|
};
|
||||||
|
|
||||||
private static bool IsWood(string prefabName) => s_woodFamily.Contains(prefabName);
|
internal static bool IsWood(string prefabName) => s_woodFamily.Contains(prefabName);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The first thing a station will take, and the chest it is in: raw material from the ENTRY chest
|
/// The first thing a station will take, and the chest it is in: raw material from the ENTRY chest
|
||||||
|
|
|
||||||
|
|
@ -105,6 +105,10 @@ namespace RacesOfValheim
|
||||||
|
|
||||||
BaseAI ai = prefab.GetComponent<BaseAI>();
|
BaseAI ai = prefab.GetComponent<BaseAI>();
|
||||||
if (ai != null) ai.m_randomMoveRange = 5f;
|
if (ai != null) ai.m_randomMoveRange = 5f;
|
||||||
|
// A flyer's MoveTo lifts its goal to m_flyAltitudeMin above whatever solid is under it,
|
||||||
|
// the rock top included: at the vanilla height the miners hovered over a deposit out of
|
||||||
|
// reach and never struck.
|
||||||
|
if (ai != null && miner) { ai.m_flyAltitudeMin = 0.5f; ai.m_flyAltitudeMax = 2f; }
|
||||||
|
|
||||||
foreach (CharacterDrop drops in prefab.GetComponentsInChildren<CharacterDrop>(true))
|
foreach (CharacterDrop drops in prefab.GetComponentsInChildren<CharacterDrop>(true))
|
||||||
{
|
{
|
||||||
|
|
@ -251,34 +255,100 @@ namespace RacesOfValheim
|
||||||
public float Radius = 12f;
|
public float Radius = 12f;
|
||||||
public float LiveSeconds = 120f;
|
public float LiveSeconds = 120f;
|
||||||
|
|
||||||
private float born;
|
// The job lives in the drone's ZDO, not only in these fields: Valheim destroys a creature
|
||||||
|
// when its zone unloads and builds a fresh one when the zone comes back, and the fresh
|
||||||
|
// one had a zero Centre, so it searched around the world origin and stood idle. The
|
||||||
|
// birth time is network time, so a rebuilt drone does not get a new two minutes either.
|
||||||
|
private static readonly int CentreKey = "rov_graf_centre".GetStableHashCode();
|
||||||
|
private static readonly int RadiusKey = "rov_graf_radius".GetStableHashCode();
|
||||||
|
private static readonly int LifeKey = "rov_graf_life".GetStableHashCode();
|
||||||
|
private static readonly int BornKey = "rov_graf_born".GetStableHashCode();
|
||||||
|
|
||||||
|
private const float Reach = 4f;
|
||||||
|
|
||||||
|
private bool loaded;
|
||||||
|
private double bornAt;
|
||||||
private float nextStrike;
|
private float nextStrike;
|
||||||
private Component target;
|
private Component target;
|
||||||
|
private float lastDistance = -1f;
|
||||||
|
private int strikes;
|
||||||
|
private string lastHit = "none";
|
||||||
|
|
||||||
|
public static readonly List<AlfarMiner> All = new List<AlfarMiner>();
|
||||||
|
|
||||||
|
private void OnEnable() { All.Add(this); }
|
||||||
|
private void OnDisable() { All.Remove(this); }
|
||||||
|
|
||||||
private static readonly System.Reflection.MethodInfo MoveToMethod =
|
private static readonly System.Reflection.MethodInfo MoveToMethod =
|
||||||
AccessTools.Method(typeof(BaseAI), "MoveTo", new[] { typeof(float), typeof(Vector3), typeof(float), typeof(bool) });
|
AccessTools.Method(typeof(BaseAI), "MoveTo", new[] { typeof(float), typeof(Vector3), typeof(float), typeof(bool) });
|
||||||
|
|
||||||
private void Start()
|
private static double Now => ZNet.instance != null ? ZNet.instance.GetTimeSeconds() : Time.time;
|
||||||
|
|
||||||
|
/// <summary>Called by the throw right after the drone is made: the job, into the ZDO.</summary>
|
||||||
|
public void Assign(Vector3 centre, float radius, float liveSeconds)
|
||||||
{
|
{
|
||||||
born = Time.time;
|
Centre = centre;
|
||||||
|
Radius = radius;
|
||||||
|
LiveSeconds = liveSeconds;
|
||||||
|
bornAt = Now;
|
||||||
|
loaded = true;
|
||||||
|
|
||||||
|
ZNetView nview = GetComponent<ZNetView>();
|
||||||
|
if (nview == null || !nview.IsValid()) return;
|
||||||
|
ZDO zdo = nview.GetZDO();
|
||||||
|
zdo.Set(CentreKey, centre);
|
||||||
|
zdo.Set(RadiusKey, radius);
|
||||||
|
zdo.Set(LifeKey, liveSeconds);
|
||||||
|
zdo.Set(BornKey, (long)(bornAt * 1000.0));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// A drone rebuilt from its ZDO reads its job back. One with no job at all (thrown by an
|
||||||
|
/// older build) digs around where it stands, which is where it was thrown.
|
||||||
|
/// </summary>
|
||||||
|
private void Load()
|
||||||
|
{
|
||||||
|
loaded = true;
|
||||||
|
ZNetView nview = GetComponent<ZNetView>();
|
||||||
|
ZDO zdo = nview != null && nview.IsValid() ? nview.GetZDO() : null;
|
||||||
|
long born = zdo != null ? zdo.GetLong(BornKey, 0L) : 0L;
|
||||||
|
if (born == 0L)
|
||||||
|
{
|
||||||
|
Centre = transform.position;
|
||||||
|
bornAt = Now;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Centre = zdo.GetVec3(CentreKey, transform.position);
|
||||||
|
Radius = zdo.GetFloat(RadiusKey, Radius);
|
||||||
|
LiveSeconds = zdo.GetFloat(LifeKey, LiveSeconds);
|
||||||
|
bornAt = born / 1000.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool Tick(MonsterAI ai, float dt)
|
public bool Tick(MonsterAI ai, float dt)
|
||||||
{
|
{
|
||||||
if (Time.time - born >= LiveSeconds)
|
if (!loaded) Load();
|
||||||
|
|
||||||
|
if (Now - bornAt >= LiveSeconds)
|
||||||
{
|
{
|
||||||
ZNetView nview = GetComponent<ZNetView>();
|
ZNetView nview = GetComponent<ZNetView>();
|
||||||
if (nview != null && nview.IsValid() && nview.IsOwner()) ZNetScene.instance.Destroy(gameObject);
|
if (nview != null && nview.IsValid() && nview.IsOwner()) ZNetScene.instance.Destroy(gameObject);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (target == null || !target.gameObject.activeInHierarchy) target = FindDeposit();
|
// A deposit another drone just broke is still there until the end of the frame, with a
|
||||||
if (target == null) { ai.StopMoving(); return true; }
|
// dead network view: drop it and look again.
|
||||||
|
if (target == null || !target.gameObject.activeInHierarchy || !Live(target)) target = FindDeposit();
|
||||||
|
Vector3 point = Vector3.zero;
|
||||||
|
Collider area = target != null ? NearestArea(target, out point) : null;
|
||||||
|
if (area == null) { target = null; ai.StopMoving(); return true; }
|
||||||
|
|
||||||
Vector3 point = target.transform.position;
|
// Measured to the closest point of the rock, not to its root: a copper deposit's root
|
||||||
|
// sits at its base inside the mesh, so a drone aiming there stopped on top of the rock
|
||||||
|
// and never came within reach.
|
||||||
float distance = Vector3.Distance(transform.position, point);
|
float distance = Vector3.Distance(transform.position, point);
|
||||||
|
lastDistance = distance;
|
||||||
|
|
||||||
if (distance > 3.5f)
|
if (distance > Reach)
|
||||||
{
|
{
|
||||||
if (MoveToMethod != null) MoveToMethod.Invoke(ai, new object[] { dt, point + Vector3.up * 1.5f, 2f, true });
|
if (MoveToMethod != null) MoveToMethod.Invoke(ai, new object[] { dt, point + Vector3.up * 1.5f, 2f, true });
|
||||||
return true;
|
return true;
|
||||||
|
|
@ -287,15 +357,30 @@ namespace RacesOfValheim
|
||||||
ai.StopMoving();
|
ai.StopMoving();
|
||||||
if (Time.time < nextStrike) return true;
|
if (Time.time < nextStrike) return true;
|
||||||
nextStrike = Time.time + 1f;
|
nextStrike = Time.time + 1f;
|
||||||
Strike(target);
|
Strike(target, area, point);
|
||||||
|
strikes++;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static string[] names;
|
private static string[] names;
|
||||||
private static string[] Deposits => names ?? (names = AlfarNexusConfig.MinerDeposits.Value.Split(
|
private static string namesSource;
|
||||||
new[] { ',' }, System.StringSplitOptions.RemoveEmptyEntries));
|
|
||||||
|
|
||||||
private bool IsPrecious(string prefabName)
|
// Read again when the config line changes, so an edit in game counts without a restart.
|
||||||
|
private static string[] Deposits
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
string value = AlfarNexusConfig.MinerDeposits.Value;
|
||||||
|
if (names == null || namesSource != value)
|
||||||
|
{
|
||||||
|
namesSource = value;
|
||||||
|
names = value.Split(new[] { ',' }, System.StringSplitOptions.RemoveEmptyEntries);
|
||||||
|
}
|
||||||
|
return names;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static bool IsPrecious(string prefabName)
|
||||||
{
|
{
|
||||||
foreach (string wanted in Deposits)
|
foreach (string wanted in Deposits)
|
||||||
{
|
{
|
||||||
|
|
@ -310,12 +395,11 @@ namespace RacesOfValheim
|
||||||
float bestDistance = float.MaxValue;
|
float bestDistance = float.MaxValue;
|
||||||
foreach (Collider collider in Physics.OverlapSphere(Centre, Radius, ~0, QueryTriggerInteraction.Ignore))
|
foreach (Collider collider in Physics.OverlapSphere(Centre, Radius, ~0, QueryTriggerInteraction.Ignore))
|
||||||
{
|
{
|
||||||
Component deposit = collider.GetComponentInParent<MineRock5>();
|
Component deposit = DepositOf(collider);
|
||||||
if (deposit == null) deposit = collider.GetComponentInParent<MineRock>();
|
|
||||||
if (deposit == null) deposit = collider.GetComponentInParent<Destructible>();
|
|
||||||
if (deposit == null) continue;
|
if (deposit == null) continue;
|
||||||
|
|
||||||
string prefabName = Utils.GetPrefabName(deposit.gameObject);
|
if (!Live(deposit)) continue;
|
||||||
|
string prefabName = DepositName(deposit);
|
||||||
if (!IsPrecious(prefabName)) continue;
|
if (!IsPrecious(prefabName)) continue;
|
||||||
|
|
||||||
float distance = Vector3.Distance(transform.position, deposit.transform.position);
|
float distance = Vector3.Distance(transform.position, deposit.transform.position);
|
||||||
|
|
@ -324,28 +408,289 @@ namespace RacesOfValheim
|
||||||
return best;
|
return best;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Strike(Component deposit)
|
/// <summary>
|
||||||
|
/// The live hit area of the deposit closest to the drone, and the closest point on it.
|
||||||
|
/// MineRock and MineRock5 only take a hit on one of their own areas; a MineRock with an area
|
||||||
|
/// root (tin) keeps its base model collider apart, and a hit on that one is thrown away.
|
||||||
|
/// Broken areas are switched off, so only active colliders count.
|
||||||
|
/// </summary>
|
||||||
|
private Collider NearestArea(Component deposit, out Vector3 point)
|
||||||
|
{
|
||||||
|
point = Vector3.zero;
|
||||||
|
MineRock rock = deposit as MineRock;
|
||||||
|
GameObject root = rock != null && rock.m_areaRoot != null ? rock.m_areaRoot : deposit.gameObject;
|
||||||
|
|
||||||
|
Collider best = null;
|
||||||
|
float bestDistance = float.MaxValue;
|
||||||
|
foreach (Collider collider in root.GetComponentsInChildren<Collider>())
|
||||||
|
{
|
||||||
|
if (collider == null || !collider.enabled) continue;
|
||||||
|
Vector3 closest = collider.bounds.ClosestPoint(transform.position);
|
||||||
|
float distance = Vector3.Distance(transform.position, closest);
|
||||||
|
if (distance < bestDistance) { best = collider; bestDistance = distance; point = closest; }
|
||||||
|
}
|
||||||
|
return best;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Strike(Component deposit, Collider area, Vector3 point)
|
||||||
{
|
{
|
||||||
IDestructible destructible = deposit as IDestructible;
|
IDestructible destructible = deposit as IDestructible;
|
||||||
if (destructible == null) return;
|
if (destructible == null) { lastHit = $"{deposit.GetType().Name} is not IDestructible"; return; }
|
||||||
|
|
||||||
HitData hit = new HitData();
|
HitData hit = new HitData();
|
||||||
hit.m_damage.m_pickaxe = AlfarNexusConfig.MinerDamage.Value;
|
hit.m_damage.m_pickaxe = AlfarNexusConfig.MinerDamage.Value;
|
||||||
hit.m_toolTier = 100;
|
hit.m_toolTier = 100;
|
||||||
hit.m_dodgeable = false;
|
hit.m_dodgeable = false;
|
||||||
hit.m_blockable = false;
|
hit.m_blockable = false;
|
||||||
hit.m_point = deposit.transform.position;
|
hit.m_hitCollider = area;
|
||||||
hit.m_dir = (deposit.transform.position - transform.position).normalized;
|
hit.m_point = point;
|
||||||
|
hit.m_dir = (area.bounds.center - transform.position).normalized;
|
||||||
|
// Vanilla MineRock (tin) reads the attacker's ZDOID for its hit effects without a null
|
||||||
|
// check: a hit with no attacker throws before the area can break.
|
||||||
|
hit.SetAttacker(GetComponent<Character>());
|
||||||
|
|
||||||
// MineRock5 picks the piece of the rock to hurt from the collider that was hit.
|
// Overwritten by the patches below at each step the hit gets through. Vanilla runs the
|
||||||
Collider collider = deposit.GetComponentInChildren<Collider>();
|
// RPC on this machine at once when we own the deposit, so `striking` is still set then.
|
||||||
if (collider != null)
|
lastHit = "Damage not entered";
|
||||||
|
striking = this;
|
||||||
|
rpcRan = false;
|
||||||
|
try
|
||||||
{
|
{
|
||||||
hit.m_hitCollider = collider;
|
destructible.Damage(hit);
|
||||||
hit.m_point = collider.bounds.center;
|
|
||||||
|
// The F8 readout showed the hit entering Damage with every gate open and this
|
||||||
|
// machine owning the deposit, and the RPC handler never running: the routed call
|
||||||
|
// left for the network instead of being handled here. When we own the deposit,
|
||||||
|
// call its own handler directly - the same resistance, tier and break logic, only
|
||||||
|
// without the routing.
|
||||||
|
if (!rpcRan && OwnsDeposit(deposit)) StrikeDirect(deposit, area, hit);
|
||||||
|
}
|
||||||
|
finally { striking = null; }
|
||||||
|
}
|
||||||
|
|
||||||
|
private static bool rpcRan;
|
||||||
|
|
||||||
|
private static readonly System.Reflection.MethodInfo DestructibleRpc = AccessTools.Method(typeof(Destructible), "RPC_Damage");
|
||||||
|
private static readonly System.Reflection.MethodInfo MineRockRpc = AccessTools.Method(typeof(MineRock), "RPC_Hit");
|
||||||
|
private static readonly System.Reflection.MethodInfo MineRockArea = AccessTools.Method(typeof(MineRock), "GetAreaIndex");
|
||||||
|
private static readonly System.Reflection.MethodInfo MineRock5Rpc = AccessTools.Method(typeof(MineRock5), "RPC_Damage");
|
||||||
|
private static readonly System.Reflection.MethodInfo MineRock5Area = AccessTools.Method(typeof(MineRock5), "GetAreaIndex");
|
||||||
|
private static readonly System.Reflection.FieldInfo RpcIdField = AccessTools.Field(typeof(ZRoutedRpc), "m_id");
|
||||||
|
|
||||||
|
private static bool OwnsDeposit(Component deposit)
|
||||||
|
{
|
||||||
|
ZNetView nview = deposit.GetComponent<ZNetView>();
|
||||||
|
return nview != null && nview.IsValid() && nview.IsOwner();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void StrikeDirect(Component deposit, Collider area, HitData hit)
|
||||||
|
{
|
||||||
|
long sender = ZDOMan.GetSessionID();
|
||||||
|
string entry = lastHit;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (deposit is Destructible && DestructibleRpc != null)
|
||||||
|
{
|
||||||
|
DestructibleRpc.Invoke(deposit, new object[] { sender, hit });
|
||||||
|
}
|
||||||
|
else if (deposit is MineRock && MineRockRpc != null && MineRockArea != null)
|
||||||
|
{
|
||||||
|
int index = (int)MineRockArea.Invoke(deposit, new object[] { area });
|
||||||
|
if (index < 0) { lastHit = "direct: collider is not a MineRock area"; return; }
|
||||||
|
MineRockRpc.Invoke(deposit, new object[] { sender, hit, index });
|
||||||
|
}
|
||||||
|
else if (deposit is MineRock5 && MineRock5Rpc != null && MineRock5Area != null)
|
||||||
|
{
|
||||||
|
int index = (int)MineRock5Area.Invoke(deposit, new object[] { area });
|
||||||
|
if (index < 0) { lastHit = "direct: collider is not a MineRock5 area"; return; }
|
||||||
|
MineRock5Rpc.Invoke(deposit, new object[] { sender, hit, index });
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
lastHit = $"direct: no handler for {deposit.GetType().Name}";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
lastHit = $"direct, {lastHit} | before: {entry}";
|
||||||
|
}
|
||||||
|
catch (System.Exception ex)
|
||||||
|
{
|
||||||
|
System.Exception inner = ex.InnerException ?? ex;
|
||||||
|
lastHit = $"direct failed: {inner.GetType().Name}: {inner.Message}";
|
||||||
|
Jotunn.Logger.LogWarning($"[Alfar] Grafvaettir direct hit failed: {inner}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ─── F8 diagnostics: what each hit did on arrival ──────────────────────
|
||||||
|
|
||||||
|
private static AlfarMiner striking;
|
||||||
|
|
||||||
|
private static AlfarMiner MinerOf(HitData hit)
|
||||||
|
{
|
||||||
|
if (striking != null) return striking;
|
||||||
|
Character attacker = hit != null ? hit.GetAttacker() : null;
|
||||||
|
return attacker != null ? attacker.GetComponent<AlfarMiner>() : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static readonly System.Reflection.FieldInfo FirstFrameField = AccessTools.Field(typeof(Destructible), "m_firstFrame");
|
||||||
|
|
||||||
|
/// <summary>The gates in front of the RPC: whose deposit it is and whether the view is live.</summary>
|
||||||
|
private static void RecordEntry(Component deposit, string extra)
|
||||||
|
{
|
||||||
|
if (striking == null) return;
|
||||||
|
ZNetView nview = deposit.GetComponent<ZNetView>();
|
||||||
|
bool valid = nview != null && nview.IsValid();
|
||||||
|
long owner = valid ? nview.GetZDO().GetOwner() : -1L;
|
||||||
|
long me = ZDOMan.GetSessionID();
|
||||||
|
Character attacker = striking.GetComponent<Character>();
|
||||||
|
object rpcId = RpcIdField != null && ZRoutedRpc.instance != null ? RpcIdField.GetValue(ZRoutedRpc.instance) : null;
|
||||||
|
striking.lastHit = $"Damage entered{extra} valid={valid} owner={owner} session={me} rpcId={rpcId} " +
|
||||||
|
$"attackerZdo={(attacker != null ? attacker.GetZDOID().ToString() : "none")}, no RPC";
|
||||||
|
}
|
||||||
|
|
||||||
|
[HarmonyPatch(typeof(Destructible), nameof(Destructible.Damage))]
|
||||||
|
public static class Alfar_Miner_DestructibleEnter_Patch
|
||||||
|
{
|
||||||
|
public static void Prefix(Destructible __instance)
|
||||||
|
{
|
||||||
|
object first = FirstFrameField != null ? FirstFrameField.GetValue(__instance) : null;
|
||||||
|
RecordEntry(__instance, $" firstFrame={first}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[HarmonyPatch(typeof(MineRock), nameof(MineRock.Damage))]
|
||||||
|
public static class Alfar_Miner_MineRockEnter_Patch
|
||||||
|
{
|
||||||
|
public static void Prefix(MineRock __instance) => RecordEntry(__instance, "");
|
||||||
|
}
|
||||||
|
|
||||||
|
[HarmonyPatch(typeof(MineRock5), nameof(MineRock5.Damage))]
|
||||||
|
public static class Alfar_Miner_MineRock5Enter_Patch
|
||||||
|
{
|
||||||
|
public static void Prefix(MineRock5 __instance) => RecordEntry(__instance, "");
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void Record(HitData hit, string kind, float before, float after, int minTier)
|
||||||
|
{
|
||||||
|
AlfarMiner miner = MinerOf(hit);
|
||||||
|
if (miner == null) return;
|
||||||
|
if (miner == striking) rpcRan = true;
|
||||||
|
miner.lastHit = $"{kind} hp {before:0.#}->{after:0.#} dmg {hit.GetTotalDamage():0.#} " +
|
||||||
|
$"pick {hit.m_damage.m_pickaxe:0.#} tier {hit.m_toolTier}/{minTier}";
|
||||||
|
}
|
||||||
|
|
||||||
|
[HarmonyPatch(typeof(Destructible), "RPC_Damage")]
|
||||||
|
public static class Alfar_Miner_DestructibleHit_Patch
|
||||||
|
{
|
||||||
|
private static float Health(Destructible d)
|
||||||
|
{
|
||||||
|
ZNetView nview = d.GetComponent<ZNetView>();
|
||||||
|
return nview != null && nview.IsValid() ? nview.GetZDO().GetFloat(ZDOVars.s_health, d.m_health) : -1f;
|
||||||
}
|
}
|
||||||
|
|
||||||
destructible.Damage(hit);
|
public static void Prefix(Destructible __instance, HitData hit, out float __state)
|
||||||
|
{
|
||||||
|
__state = MinerOf(hit) != null ? Health(__instance) : -1f;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void Postfix(Destructible __instance, HitData hit, float __state)
|
||||||
|
{
|
||||||
|
if (MinerOf(hit) == null) return;
|
||||||
|
Record(hit, "Destructible", __state, Health(__instance), __instance.m_minToolTier);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[HarmonyPatch(typeof(MineRock), "RPC_Hit")]
|
||||||
|
public static class Alfar_Miner_MineRockHit_Patch
|
||||||
|
{
|
||||||
|
private static float Health(MineRock rock, int area)
|
||||||
|
{
|
||||||
|
ZNetView nview = rock.GetComponent<ZNetView>();
|
||||||
|
return nview != null && nview.IsValid() ? nview.GetZDO().GetFloat("Health" + area, rock.GetHealth()) : -1f;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void Prefix(MineRock __instance, HitData hit, int hitAreaIndex, out float __state)
|
||||||
|
{
|
||||||
|
__state = MinerOf(hit) != null ? Health(__instance, hitAreaIndex) : -1f;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void Postfix(MineRock __instance, HitData hit, int hitAreaIndex, float __state)
|
||||||
|
{
|
||||||
|
if (MinerOf(hit) == null) return;
|
||||||
|
Record(hit, $"MineRock area {hitAreaIndex}", __state, Health(__instance, hitAreaIndex), __instance.m_minToolTier);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[HarmonyPatch(typeof(MineRock5), "DamageArea")]
|
||||||
|
public static class Alfar_Miner_MineRock5Hit_Patch
|
||||||
|
{
|
||||||
|
public static void Postfix(MineRock5 __instance, int hitAreaIndex, HitData hit, bool __result)
|
||||||
|
{
|
||||||
|
if (MinerOf(hit) == null) return;
|
||||||
|
Record(hit, $"MineRock5 area {hitAreaIndex} damaged={__result}", -1f, -1f, __instance.m_minToolTier);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static bool Live(Component deposit)
|
||||||
|
{
|
||||||
|
ZNetView nview = deposit.GetComponent<ZNetView>();
|
||||||
|
return nview != null && nview.IsValid();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The deposit's prefab name, read from its ZDO. Not from the GameObject: MineRock5 renames
|
||||||
|
/// its own object to "___MineRock5 m_meshFilter" in Awake, so a broken copper vein
|
||||||
|
/// (rock4_copper_frac) never matched the list and the drones stopped after the first blow.
|
||||||
|
/// </summary>
|
||||||
|
private static string DepositName(Component deposit)
|
||||||
|
{
|
||||||
|
ZNetView nview = deposit.GetComponent<ZNetView>();
|
||||||
|
if (nview != null && nview.IsValid() && ZNetScene.instance != null)
|
||||||
|
{
|
||||||
|
GameObject prefab = ZNetScene.instance.GetPrefab(nview.GetZDO().GetPrefab());
|
||||||
|
if (prefab != null) return prefab.name;
|
||||||
|
}
|
||||||
|
return Utils.GetPrefabName(deposit.gameObject);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Component DepositOf(Collider collider)
|
||||||
|
{
|
||||||
|
Component deposit = collider.GetComponentInParent<MineRock5>();
|
||||||
|
if (deposit == null) deposit = collider.GetComponentInParent<MineRock>();
|
||||||
|
if (deposit == null) deposit = collider.GetComponentInParent<Destructible>();
|
||||||
|
return deposit;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// F8 readout: what the camera looks at (is it a deposit, of which kind, on the list?) and
|
||||||
|
/// what each live miner is doing (its target, how far, how many strikes).
|
||||||
|
/// </summary>
|
||||||
|
public static void DebugReport(Player player)
|
||||||
|
{
|
||||||
|
var lines = new List<string>();
|
||||||
|
Transform aim = GameCamera.instance != null ? GameCamera.instance.transform : player.transform;
|
||||||
|
if (Physics.Raycast(aim.position, aim.forward, out RaycastHit hit, 50f, ~0, QueryTriggerInteraction.Ignore))
|
||||||
|
{
|
||||||
|
Component deposit = DepositOf(hit.collider);
|
||||||
|
string prefabName = deposit != null ? DepositName(deposit) : Utils.GetPrefabName(hit.collider.transform.root.gameObject);
|
||||||
|
lines.Add($"[RoV graf] look: {hit.collider.name} on {prefabName} " +
|
||||||
|
(deposit != null ? $"{deposit.GetType().Name} listed={IsPrecious(prefabName)}" : "not a deposit"));
|
||||||
|
}
|
||||||
|
else lines.Add("[RoV graf] look: nothing within 50m");
|
||||||
|
|
||||||
|
foreach (AlfarMiner miner in All)
|
||||||
|
{
|
||||||
|
if (miner == null) continue;
|
||||||
|
string targetName = miner.target != null ? DepositName(miner.target) : "none";
|
||||||
|
lines.Add($"[RoV graf] miner {Vector3.Distance(miner.transform.position, player.transform.position):0}m away: " +
|
||||||
|
$"target {targetName} dist {miner.lastDistance:0.0} strikes {miner.strikes} " +
|
||||||
|
$"age {Now - miner.bornAt:0}s centre {miner.Centre} r {miner.Radius:0} | last hit: {miner.lastHit}");
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (string line in lines)
|
||||||
|
{
|
||||||
|
Debug.Log(line);
|
||||||
|
player.Message(MessageHud.MessageType.TopLeft, line);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[HarmonyPatch(typeof(MonsterAI), "UpdateAI")]
|
[HarmonyPatch(typeof(MonsterAI), "UpdateAI")]
|
||||||
|
|
|
||||||
166
JotunnModStub/Alfar/AlfarFireChest.cs
Normal file
|
|
@ -0,0 +1,166 @@
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using Jotunn.Managers;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace RacesOfValheim
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The Eldividarkista's own body. Players kept mistaking a plain "Wood chest" for it, so it must
|
||||||
|
/// not look like any chest they can build: the box and lid are the Mistlands dvergr crate (a prop
|
||||||
|
/// nobody can place), repainted as blackened iron with an aged-bronze frame
|
||||||
|
/// (scripts/paint_fire_chest.py), with an iron grate on the front.
|
||||||
|
///
|
||||||
|
/// Behind the grate the fire shows only while the chest holds wood the drones may burn: a dark
|
||||||
|
/// grate means empty. No light source, on purpose - a base full of chests must not glow.
|
||||||
|
/// </summary>
|
||||||
|
public static class AlfarFireChest
|
||||||
|
{
|
||||||
|
private const string CrateName = "dvergrprops_crate";
|
||||||
|
private const string EmbersSource = "fx_Torch_Carried";
|
||||||
|
|
||||||
|
// The crate is a 1.02 m cube, stretched into a chest about the size of the vanilla one:
|
||||||
|
// 1.6 m wide, 0.8 m deep. Its front face (+z, away from the lid's hinge) ends up here.
|
||||||
|
private static readonly Vector3 Stretch = new Vector3(1.6f, 1f, 0.8f);
|
||||||
|
private const float FrontZ = 0.515f * 0.8f;
|
||||||
|
private const float LidY = 0.81f;
|
||||||
|
private const float GrateWidth = 0.62f * 1.6f;
|
||||||
|
private const int GrateGaps = 10;
|
||||||
|
private const float GrateHeight = 0.36f;
|
||||||
|
private const float GrateY = 0.42f;
|
||||||
|
|
||||||
|
private static readonly Color Ember = new Color(1f, 0.42f, 0.1f);
|
||||||
|
|
||||||
|
/// <summary>Swaps the cloned wood chest's meshes for the fire chest. False leaves the wood
|
||||||
|
/// chest's look in place, with a warning, rather than an invisible chest.</summary>
|
||||||
|
public static bool Build(GameObject prefab)
|
||||||
|
{
|
||||||
|
GameObject crate = PrefabManager.Cache.GetPrefab<GameObject>(CrateName);
|
||||||
|
Transform crateNew = crate != null ? crate.transform.Find("new") : null;
|
||||||
|
Transform visual = prefab.transform.Find("New");
|
||||||
|
if (crateNew == null || crateNew.childCount < 3 || visual == null)
|
||||||
|
{
|
||||||
|
Jotunn.Logger.LogWarning("[Alfar] No dvergr crate to build the Eldividarkista from; it keeps the wood chest's look.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// The wood chest's box, lids and LOD group go; "New" itself stays, because WearNTear
|
||||||
|
// switches it as the piece's healthy look.
|
||||||
|
for (int i = visual.childCount - 1; i >= 0; i--) Object.DestroyImmediate(visual.GetChild(i).gameObject);
|
||||||
|
LODGroup lod = visual.GetComponent<LODGroup>();
|
||||||
|
if (lod != null) Object.DestroyImmediate(lod);
|
||||||
|
|
||||||
|
// The crate's high meshes, in the order the prefab keeps them: box, contents, lid. The
|
||||||
|
// contents are the glowing dvergr cargo and stay behind.
|
||||||
|
GameObject body = Object.Instantiate(crateNew.GetChild(0).gameObject, visual, false);
|
||||||
|
body.name = "body";
|
||||||
|
body.transform.localScale = Vector3.Scale(body.transform.localScale, Stretch);
|
||||||
|
GameObject lidClosed = Object.Instantiate(crateNew.GetChild(2).gameObject, visual, false);
|
||||||
|
lidClosed.name = "lid_closed";
|
||||||
|
lidClosed.transform.localScale = Vector3.Scale(lidClosed.transform.localScale, Stretch);
|
||||||
|
|
||||||
|
// The open lid: the closed one turned up 100 degrees about its back edge.
|
||||||
|
GameObject lidOpen = Object.Instantiate(lidClosed, visual, false);
|
||||||
|
lidOpen.name = "lid_open";
|
||||||
|
foreach (Collider collider in lidOpen.GetComponentsInChildren<Collider>(true)) Object.DestroyImmediate(collider);
|
||||||
|
Vector3 hinge = new Vector3(0f, LidY, -FrontZ);
|
||||||
|
Quaternion turn = Quaternion.Euler(-100f, 0f, 0f);
|
||||||
|
lidOpen.transform.localPosition = hinge + turn * (lidClosed.transform.localPosition - hinge);
|
||||||
|
lidOpen.transform.localRotation = turn * lidClosed.transform.localRotation;
|
||||||
|
lidOpen.SetActive(false);
|
||||||
|
|
||||||
|
Container container = prefab.GetComponent<Container>();
|
||||||
|
if (container != null)
|
||||||
|
{
|
||||||
|
container.m_open = lidOpen;
|
||||||
|
container.m_closed = lidClosed;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Only a retextured material is a copy; without the paint, writing to it would change every
|
||||||
|
// dvergr crate in the Mistlands too.
|
||||||
|
Texture2D paint = PieceLook.LoadTexture("AlfarFireChest_d.png");
|
||||||
|
if (paint != null) PieceLook.Retexture(visual, new Dictionary<string, Texture> { { "Crate_d", paint } });
|
||||||
|
Material iron = paint != null ? body.GetComponent<MeshRenderer>()?.sharedMaterial : null;
|
||||||
|
if (iron != null)
|
||||||
|
{
|
||||||
|
// The crate's normal map is wood planks; on plates it would draw seams that are not there.
|
||||||
|
if (iron.HasProperty("_BumpMap")) iron.SetTexture("_BumpMap", null);
|
||||||
|
if (iron.HasProperty("_Metallic")) iron.SetFloat("_Metallic", 0.6f);
|
||||||
|
if (iron.HasProperty("_Glossiness")) iron.SetFloat("_Glossiness", 0.45f);
|
||||||
|
}
|
||||||
|
|
||||||
|
Transform grate = BuildGrate(visual, iron, out Renderer glow);
|
||||||
|
ParticleSystem embers = AddEmbers(grate);
|
||||||
|
|
||||||
|
AlfarChestGlow look = prefab.AddComponent<AlfarChestGlow>();
|
||||||
|
look.Glows = new[] { glow };
|
||||||
|
look.Embers = embers;
|
||||||
|
look.GlowColor = Ember * 2f;
|
||||||
|
look.WoodOnly = true;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>The grate: a glowing plate just off the front face, a frame and bars in front of it.</summary>
|
||||||
|
private static Transform BuildGrate(Transform visual, Material iron, out Renderer glow)
|
||||||
|
{
|
||||||
|
Transform grate = new GameObject("grate").transform;
|
||||||
|
grate.SetParent(visual, false);
|
||||||
|
grate.gameObject.layer = visual.gameObject.layer;
|
||||||
|
|
||||||
|
Material bars = iron != null ? new Material(iron) { name = "AlfarFireChest_bars" } : null;
|
||||||
|
if (bars != null)
|
||||||
|
{
|
||||||
|
bars.SetTexture("_MainTex", null);
|
||||||
|
bars.color = new Color(0.16f, 0.15f, 0.15f);
|
||||||
|
}
|
||||||
|
|
||||||
|
glow = Block(grate, "glow", new Vector3(0f, GrateY, FrontZ + 0.005f), new Vector3(GrateWidth, GrateHeight, 0.01f), bars).GetComponent<Renderer>();
|
||||||
|
|
||||||
|
const float frame = 0.035f;
|
||||||
|
foreach (float x in new[] { -GrateWidth / 2f, GrateWidth / 2f })
|
||||||
|
Block(grate, "frame", new Vector3(x, GrateY, FrontZ + 0.02f), new Vector3(frame, GrateHeight + frame, 0.04f), bars);
|
||||||
|
foreach (float y in new[] { GrateY - GrateHeight / 2f, GrateY + GrateHeight / 2f })
|
||||||
|
Block(grate, "frame", new Vector3(0f, y, FrontZ + 0.02f), new Vector3(GrateWidth + frame, frame, 0.04f), bars);
|
||||||
|
|
||||||
|
for (int i = 1; i < GrateGaps; i++)
|
||||||
|
{
|
||||||
|
float x = -GrateWidth / 2f + GrateWidth * i / GrateGaps;
|
||||||
|
Block(grate, "bar", new Vector3(x, GrateY, FrontZ + 0.02f), new Vector3(0.022f, GrateHeight, 0.03f), bars);
|
||||||
|
}
|
||||||
|
Block(grate, "bar", new Vector3(0f, GrateY, FrontZ + 0.022f), new Vector3(GrateWidth, 0.022f, 0.03f), bars);
|
||||||
|
|
||||||
|
return grate;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>A plain box with no collider, for trim the borrowed meshes do not have.</summary>
|
||||||
|
internal static GameObject Block(Transform parent, string name, Vector3 position, Vector3 size, Material material)
|
||||||
|
{
|
||||||
|
GameObject block = GameObject.CreatePrimitive(PrimitiveType.Cube);
|
||||||
|
Object.DestroyImmediate(block.GetComponent<Collider>());
|
||||||
|
block.name = name;
|
||||||
|
block.layer = parent.gameObject.layer;
|
||||||
|
block.transform.SetParent(parent, false);
|
||||||
|
block.transform.localPosition = position;
|
||||||
|
block.transform.localScale = size;
|
||||||
|
if (material != null) block.GetComponent<Renderer>().sharedMaterial = material;
|
||||||
|
return block;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>The carried torch's embers, rising off the top of the grate.</summary>
|
||||||
|
private static ParticleSystem AddEmbers(Transform grate)
|
||||||
|
{
|
||||||
|
GameObject torch = PrefabManager.Cache.GetPrefab<GameObject>(EmbersSource);
|
||||||
|
Transform source = torch != null ? torch.transform.Find("Embers") : null;
|
||||||
|
if (source == null)
|
||||||
|
{
|
||||||
|
Jotunn.Logger.LogWarning("[Alfar] No torch embers for the Eldividarkista; its grate glows without sparks.");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
GameObject embers = Object.Instantiate(source.gameObject, grate, false);
|
||||||
|
embers.name = "embers";
|
||||||
|
embers.transform.localPosition = new Vector3(0f, GrateY + GrateHeight / 2f, FrontZ + 0.05f);
|
||||||
|
embers.transform.localRotation = Quaternion.identity;
|
||||||
|
return embers.GetComponent<ParticleSystem>();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
137
JotunnModStub/Alfar/AlfarInputChest.cs
Normal file
|
|
@ -0,0 +1,137 @@
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using Jotunn.Managers;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace RacesOfValheim
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The Inngangskista's own body, the cold twin of <see cref="AlfarFireChest"/>: the dvergr loot
|
||||||
|
/// chest of the Mistlands towns (seen, never built), its panels repainted navy steel
|
||||||
|
/// (scripts/paint_input_chest.py) and its copper trim turned silver. A cyan line set into the
|
||||||
|
/// lid shines while the chest holds anything for the drones, and goes dark once they have
|
||||||
|
/// emptied it.
|
||||||
|
/// </summary>
|
||||||
|
public static class AlfarInputChest
|
||||||
|
{
|
||||||
|
private const string SourceName = "TreasureChest_dvergrtown";
|
||||||
|
|
||||||
|
// The town chest is placed at 1.2 and its meshes at 1.5 on top: 1.66 m wide, a vanilla chest's size.
|
||||||
|
private const float SourceScale = 1.2f;
|
||||||
|
private const float MeshScale = 1.5f * SourceScale;
|
||||||
|
private const float LidTop = 0.48f * MeshScale;
|
||||||
|
private const float LidHalfX = 0.42f * MeshScale;
|
||||||
|
private const float LidHalfZ = 0.24f * MeshScale;
|
||||||
|
private const float InlayInset = 0.10f;
|
||||||
|
private const float InlayWidth = 0.03f;
|
||||||
|
|
||||||
|
private static readonly Color Trim = new Color(0.9f, 0.95f, 1f);
|
||||||
|
private static readonly Color Inlay = new Color(0.35f, 0.9f, 1f);
|
||||||
|
|
||||||
|
/// <summary>Swaps the cloned wood chest's meshes for the input chest. False leaves the wood
|
||||||
|
/// chest's look in place, with a warning.</summary>
|
||||||
|
public static bool Build(GameObject prefab)
|
||||||
|
{
|
||||||
|
GameObject source = PrefabManager.Cache.GetPrefab<GameObject>(SourceName);
|
||||||
|
Transform sourceNew = source != null ? source.transform.Find("New") : null;
|
||||||
|
Transform box = sourceNew != null ? sourceNew.Find("stonechest") : null;
|
||||||
|
Transform closed = sourceNew != null ? sourceNew.Find("stonechesttop_closed") : null;
|
||||||
|
Transform open = sourceNew != null ? sourceNew.Find("stonechesttop_open") : null;
|
||||||
|
Transform visual = prefab.transform.Find("New");
|
||||||
|
if (box == null || closed == null || open == null || visual == null)
|
||||||
|
{
|
||||||
|
Jotunn.Logger.LogWarning("[Alfar] No dvergr chest to build the Inngangskista from; it keeps the wood chest's look.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = visual.childCount - 1; i >= 0; i--) Object.DestroyImmediate(visual.GetChild(i).gameObject);
|
||||||
|
LODGroup lod = visual.GetComponent<LODGroup>();
|
||||||
|
if (lod != null) Object.DestroyImmediate(lod);
|
||||||
|
|
||||||
|
GameObject body = Copy(box, visual, "body");
|
||||||
|
GameObject lidClosed = Copy(closed, visual, "lid_closed");
|
||||||
|
GameObject lidOpen = Copy(open, visual, "lid_open");
|
||||||
|
lidOpen.SetActive(false);
|
||||||
|
|
||||||
|
Container container = prefab.GetComponent<Container>();
|
||||||
|
if (container != null)
|
||||||
|
{
|
||||||
|
container.m_open = lidOpen;
|
||||||
|
container.m_closed = lidClosed;
|
||||||
|
}
|
||||||
|
|
||||||
|
Texture2D paint = PieceLook.LoadTexture("AlfarInputChest_d.png");
|
||||||
|
if (paint == null) return true; // the dvergr chest as it is: still not a vanilla chest
|
||||||
|
PieceLook.Retexture(visual, new Dictionary<string, Texture> { { "dvergrchestWorn_d", paint } });
|
||||||
|
|
||||||
|
// The trim shares the anvil's texture, so it is recoloured on a copy instead; the panels'
|
||||||
|
// material is already a copy from Retexture.
|
||||||
|
var copies = new Dictionary<Material, Material>();
|
||||||
|
Material panel = null;
|
||||||
|
foreach (Renderer renderer in visual.GetComponentsInChildren<Renderer>(true))
|
||||||
|
{
|
||||||
|
Material[] materials = renderer.sharedMaterials;
|
||||||
|
for (int i = 0; i < materials.Length; i++)
|
||||||
|
{
|
||||||
|
Material material = materials[i];
|
||||||
|
if (material == null) continue;
|
||||||
|
if (material.name.EndsWith("_rov")) { panel = panel ?? material; continue; }
|
||||||
|
if (!material.name.StartsWith("dvergr_metal_furnmiture")) continue;
|
||||||
|
|
||||||
|
if (!copies.TryGetValue(material, out Material trim))
|
||||||
|
{
|
||||||
|
trim = new Material(material) { name = material.name + "_rov" };
|
||||||
|
trim.color = Trim;
|
||||||
|
if (trim.HasProperty("_MetalColor")) trim.SetColor("_MetalColor", Trim);
|
||||||
|
copies[material] = trim;
|
||||||
|
}
|
||||||
|
materials[i] = trim;
|
||||||
|
}
|
||||||
|
renderer.sharedMaterials = materials;
|
||||||
|
}
|
||||||
|
|
||||||
|
AlfarChestGlow look = prefab.AddComponent<AlfarChestGlow>();
|
||||||
|
look.Glows = BuildInlay(lidClosed.transform, panel);
|
||||||
|
look.GlowColor = Inlay * 1.6f;
|
||||||
|
look.WoodOnly = false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>A copy of one of the town chest's parts, at the town chest's size and on the piece layer.</summary>
|
||||||
|
private static GameObject Copy(Transform part, Transform parent, string name)
|
||||||
|
{
|
||||||
|
GameObject copy = Object.Instantiate(part.gameObject, parent, false);
|
||||||
|
copy.name = name;
|
||||||
|
copy.transform.localPosition = part.localPosition * SourceScale;
|
||||||
|
copy.transform.localScale = part.localScale * SourceScale;
|
||||||
|
foreach (Transform t in copy.GetComponentsInChildren<Transform>(true)) t.gameObject.layer = parent.gameObject.layer;
|
||||||
|
return copy;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>The cyan line on the lid: four thin strips just above it, inset from the edge. They
|
||||||
|
/// hang off the closed lid, so they go with it when the chest opens. The lid is scaled, so the
|
||||||
|
/// sizes are divided back out of it.</summary>
|
||||||
|
private static Renderer[] BuildInlay(Transform lid, Material panel)
|
||||||
|
{
|
||||||
|
Material cold = panel != null ? new Material(panel) { name = "AlfarInputChest_inlay" } : null;
|
||||||
|
if (cold != null)
|
||||||
|
{
|
||||||
|
cold.SetTexture("_MainTex", null);
|
||||||
|
cold.color = new Color(0.08f, 0.12f, 0.16f);
|
||||||
|
}
|
||||||
|
|
||||||
|
float k = 1f / lid.localScale.x;
|
||||||
|
float x = LidHalfX - InlayInset, z = LidHalfZ - InlayInset, y = LidTop + 0.004f;
|
||||||
|
var strips = new List<Renderer>();
|
||||||
|
foreach (float side in new[] { -z, z })
|
||||||
|
strips.Add(Strip(lid, new Vector3(0f, y, side) * k, new Vector3(2f * x + InlayWidth, 0.01f, InlayWidth) * k, cold));
|
||||||
|
foreach (float side in new[] { -x, x })
|
||||||
|
strips.Add(Strip(lid, new Vector3(side, y, 0f) * k, new Vector3(InlayWidth, 0.01f, 2f * z) * k, cold));
|
||||||
|
return strips.ToArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Renderer Strip(Transform lid, Vector3 position, Vector3 size, Material material)
|
||||||
|
{
|
||||||
|
return AlfarFireChest.Block(lid, "inlay", position, size, material).GetComponent<Renderer>();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -48,7 +48,7 @@ namespace RacesOfValheim
|
||||||
float target = 0f;
|
float target = 0f;
|
||||||
if (Time.time - AlfarArchon.StartedAt < 0.6f) target = 4f; // lift off
|
if (Time.time - AlfarArchon.StartedAt < 0.6f) target = 4f; // lift off
|
||||||
else if (RaceInput.Allowed && JumpHeld()) target = speed;
|
else if (RaceInput.Allowed && JumpHeld()) target = speed;
|
||||||
else if (RaceInput.Allowed && ZInput.GetButton("Crouch")) target = -speed;
|
else if (RaceInput.Allowed && CrouchHeld()) target = -speed;
|
||||||
|
|
||||||
Vector3 velocity = flyer.linearVelocity;
|
Vector3 velocity = flyer.linearVelocity;
|
||||||
velocity.y = Mathf.Lerp(velocity.y, target, 0.25f);
|
velocity.y = Mathf.Lerp(velocity.y, target, 0.25f);
|
||||||
|
|
@ -97,9 +97,15 @@ namespace RacesOfValheim
|
||||||
|
|
||||||
private static bool JumpHeld()
|
private static bool JumpHeld()
|
||||||
{
|
{
|
||||||
// ZInput's "Jump" covers the space bar and the pad's jump button alike, and respects the
|
// "Jump" is the keyboard binding only; the pad's button is a separate "JoyJump", read
|
||||||
// controls the player picked in the settings.
|
// the way PlayerController reads it, kept off while a radial menu has the pad.
|
||||||
return ZInput.GetButton("Jump");
|
return ZInput.GetButton("Jump") || (ZInput.GetButton("JoyJump") && !Hud.InRadial());
|
||||||
|
}
|
||||||
|
|
||||||
|
private static bool CrouchHeld()
|
||||||
|
{
|
||||||
|
// Same split as jump: PlayerController ORs "Crouch" with "JoyCrouch".
|
||||||
|
return ZInput.GetButton("Crouch") || (ZInput.GetButton("JoyCrouch") && !Hud.InRadial());
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void FlushSpend(Player player)
|
private static void FlushSpend(Player player)
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,11 @@ namespace RacesOfValheim
|
||||||
|
|
||||||
public static void Throw(Player player)
|
public static void Throw(Player player)
|
||||||
{
|
{
|
||||||
if (Time.time < readyAt) return;
|
if (Time.time < readyAt)
|
||||||
|
{
|
||||||
|
player.Message(MessageHud.MessageType.Center, ModText.Get("rov_msg_alfar_graf_cooldown", Mathf.CeilToInt(readyAt - Time.time)));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
Transform aim = GameCamera.instance != null ? GameCamera.instance.transform : player.transform;
|
Transform aim = GameCamera.instance != null ? GameCamera.instance.transform : player.transform;
|
||||||
Vector3 origin = aim.position;
|
Vector3 origin = aim.position;
|
||||||
|
|
@ -76,12 +80,7 @@ namespace RacesOfValheim
|
||||||
GameObject spawned = Object.Instantiate(prefab, where, Quaternion.identity);
|
GameObject spawned = Object.Instantiate(prefab, where, Quaternion.identity);
|
||||||
|
|
||||||
AlfarMiner miner = spawned.GetComponent<AlfarMiner>();
|
AlfarMiner miner = spawned.GetComponent<AlfarMiner>();
|
||||||
if (miner != null)
|
if (miner != null) miner.Assign(point, AlfarPowerConfig.GrafRadius.Value, AlfarPowerConfig.GrafSeconds.Value);
|
||||||
{
|
|
||||||
miner.Centre = point;
|
|
||||||
miner.Radius = AlfarPowerConfig.GrafRadius.Value;
|
|
||||||
miner.LiveSeconds = AlfarPowerConfig.GrafSeconds.Value;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Tame at once so nothing flees them and they flee nothing; no anchor, no leash.
|
// Tame at once so nothing flees them and they flee nothing; no anchor, no leash.
|
||||||
MonsterAI ai = spawned.GetComponent<MonsterAI>();
|
MonsterAI ai = spawned.GetComponent<MonsterAI>();
|
||||||
|
|
|
||||||
|
|
@ -46,7 +46,9 @@ namespace RacesOfValheim
|
||||||
Object.DestroyImmediate(behaviour);
|
Object.DestroyImmediate(behaviour);
|
||||||
}
|
}
|
||||||
|
|
||||||
AlfarConstructs.Tint(prefab, new Color(0.62f, 0.8f, 1f, 1f));
|
// The floating pyramid; the blue table stays as the fallback if it cannot be built.
|
||||||
|
bool pyramid = AlfarNexusLook.Build(prefab);
|
||||||
|
if (!pyramid) AlfarConstructs.Tint(prefab, new Color(0.62f, 0.8f, 1f, 1f));
|
||||||
|
|
||||||
AlfarNexusBehaviour nexus = prefab.AddComponent<AlfarNexusBehaviour>();
|
AlfarNexusBehaviour nexus = prefab.AddComponent<AlfarNexusBehaviour>();
|
||||||
nexus.m_switch = prefab.AddComponent<Switch>();
|
nexus.m_switch = prefab.AddComponent<Switch>();
|
||||||
|
|
@ -71,7 +73,7 @@ namespace RacesOfValheim
|
||||||
trader.m_randomUseItemAlreadyRecieved = new List<string>();
|
trader.m_randomUseItemAlreadyRecieved = new List<string>();
|
||||||
trader.m_randomTalkConditionals = new List<Trader.ConditionalDialog>();
|
trader.m_randomTalkConditionals = new List<Trader.ConditionalDialog>();
|
||||||
|
|
||||||
Sprite icon = BorrowIcon("Eitr") ?? BorrowIcon("SurtlingCore");
|
Sprite icon = (pyramid ? AlfarChests.IconFrom("AlfarNexus_icon.png") : null) ?? BorrowIcon("Eitr") ?? BorrowIcon("SurtlingCore");
|
||||||
|
|
||||||
Piece piece = prefab.GetComponent<Piece>() ?? prefab.AddComponent<Piece>();
|
Piece piece = prefab.GetComponent<Piece>() ?? prefab.AddComponent<Piece>();
|
||||||
piece.m_craftingStation = null;
|
piece.m_craftingStation = null;
|
||||||
|
|
|
||||||
|
|
@ -89,8 +89,13 @@ namespace RacesOfValheim
|
||||||
DroneZapDamage = config.Bind(drone, "Zap Damage", 1f, new ConfigDescription("Lightning damage of a drone's defensive zap.", new AcceptableValueRange<float>(0f, 100f)));
|
DroneZapDamage = config.Bind(drone, "Zap Damage", 1f, new ConfigDescription("Lightning damage of a drone's defensive zap.", new AcceptableValueRange<float>(0f, 100f)));
|
||||||
DroneZapInterval = config.Bind(drone, "Zap Interval", 2f, new ConfigDescription("Seconds between a drone's zaps.", new AcceptableValueRange<float>(0.2f, 30f)));
|
DroneZapInterval = config.Bind(drone, "Zap Interval", 2f, new ConfigDescription("Seconds between a drone's zaps.", new AcceptableValueRange<float>(0.2f, 30f)));
|
||||||
|
|
||||||
MinerDeposits = config.Bind(drone, "Mining Targets", "MineRock_Copper,MineRock_Tin,MineRock_Iron,silvervein,rock3_silver,giant_brain",
|
// Copper deposits are rock4_copper (and rock4_copper_frac once hit), crypt scrap is mudpile;
|
||||||
|
// the first default missed both, so a config still holding it is moved to the new one.
|
||||||
|
const string oldTargets = "MineRock_Copper,MineRock_Tin,MineRock_Iron,silvervein,rock3_silver,giant_brain";
|
||||||
|
const string targets = "rock4_copper,MineRock_Copper,MineRock_Tin,MineRock_Iron,mudpile,silvervein,rock3_silver,giant_brain";
|
||||||
|
MinerDeposits = config.Bind(drone, "Mining Targets", targets,
|
||||||
new ConfigDescription("Comma separated parts of prefab names the mining drones dig (case does not matter). Soft tissue comes from giant_brain."));
|
new ConfigDescription("Comma separated parts of prefab names the mining drones dig (case does not matter). Soft tissue comes from giant_brain."));
|
||||||
|
if (MinerDeposits.Value == oldTargets) MinerDeposits.Value = targets;
|
||||||
MinerDamage = config.Bind(drone, "Mining Damage", 40f, new ConfigDescription("Pickaxe damage each mining drone does per second to a deposit.", new AcceptableValueRange<float>(1f, 1000f)));
|
MinerDamage = config.Bind(drone, "Mining Damage", 40f, new ConfigDescription("Pickaxe damage each mining drone does per second to a deposit.", new AcceptableValueRange<float>(1f, 1000f)));
|
||||||
|
|
||||||
WildPickables = config.Bind(drone, "Wild Plants Harvested", "Pickable_Mushroom,Pickable_Dandelion,Pickable_Thistle,RaspberryBush,BlueberryBush,CloudberryBush",
|
WildPickables = config.Bind(drone, "Wild Plants Harvested", "Pickable_Mushroom,Pickable_Dandelion,Pickable_Thistle,RaspberryBush,BlueberryBush,CloudberryBush",
|
||||||
|
|
|
||||||
217
JotunnModStub/Alfar/AlfarNexusLook.cs
Normal file
|
|
@ -0,0 +1,217 @@
|
||||||
|
using Jotunn.Managers;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace RacesOfValheim
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The Ljoskjarne's body: a stone pyramid, 2 m to a side and 2 m tall, floating 0.8 m above the
|
||||||
|
/// ground. Dark steel carved with Valheim's own runes (the Ashlands rune tile's glyphs, laid out by
|
||||||
|
/// scripts/paint_nexus.py), and a cyan seam down the middle of each face.
|
||||||
|
///
|
||||||
|
/// The seam is painted into the faces' glow map, not built. Bars standing on the faces, lit or
|
||||||
|
/// unlit, lost part of their length to the face on whichever side looked one way in the world,
|
||||||
|
/// as the pyramid turned; a line in the face's own pixels has nothing to hide behind.
|
||||||
|
///
|
||||||
|
/// Only the look moves. The piece keeps one still collider from the ground up, so building on it,
|
||||||
|
/// support, hovering and the E key behave as before; the pyramid bobs and turns on each client by
|
||||||
|
/// itself, nothing over the network. The seam breathes, and burns brighter while crystals wait.
|
||||||
|
/// </summary>
|
||||||
|
public static class AlfarNexusLook
|
||||||
|
{
|
||||||
|
private const float Height = 2f;
|
||||||
|
private const float HalfBase = 1f;
|
||||||
|
private const float Lift = 0.8f;
|
||||||
|
private const string SourceMaterialPrefab = "piece_cartographytable";
|
||||||
|
private const string EmbersSource = "fx_Torch_Carried";
|
||||||
|
|
||||||
|
private static readonly Color Seam = new Color(0.35f, 0.75f, 1f);
|
||||||
|
|
||||||
|
/// <summary>Strips the cartography table's body and puts the pyramid in its place. False leaves
|
||||||
|
/// the table, with a warning, so the Nexus is never invisible.</summary>
|
||||||
|
public static bool Build(GameObject prefab)
|
||||||
|
{
|
||||||
|
Texture2D face = PieceLook.LoadTexture("AlfarNexus_face.png");
|
||||||
|
Texture2D glow = PieceLook.LoadTexture("AlfarNexus_glow.png");
|
||||||
|
Texture2D bumps = PieceLook.LoadTexture("AlfarNexus_n.png", true);
|
||||||
|
Renderer tableRenderer = prefab.transform.Find("new/high")?.GetComponent<Renderer>();
|
||||||
|
if (face == null || glow == null || tableRenderer == null || tableRenderer.sharedMaterial == null)
|
||||||
|
{
|
||||||
|
Jotunn.Logger.LogWarning("[Alfar] Could not build the Ljoskjarne's pyramid; it keeps the cartography table's look.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Material stone = new Material(tableRenderer.sharedMaterial) { name = "AlfarNexus_stone" };
|
||||||
|
stone.color = Color.white;
|
||||||
|
stone.SetTexture("_MainTex", face);
|
||||||
|
// Forged, not polished: the plate's own grain in the normal map, and a dull sheen.
|
||||||
|
stone.SetTexture("_BumpMap", bumps);
|
||||||
|
if (bumps != null) stone.EnableKeyword("_NORMALMAP");
|
||||||
|
else stone.DisableKeyword("_NORMALMAP");
|
||||||
|
if (stone.HasProperty("_MetallicGlossMap")) stone.SetTexture("_MetallicGlossMap", null);
|
||||||
|
if (stone.HasProperty("_Metallic")) stone.SetFloat("_Metallic", 0.6f);
|
||||||
|
if (stone.HasProperty("_Glossiness")) stone.SetFloat("_Glossiness", 0.3f);
|
||||||
|
// Custom/Piece samples its noise in world space unless told the object moves, as boats and
|
||||||
|
// carts do; on a turning pyramid the blotches would slide across the faces.
|
||||||
|
stone.EnableKeyword("_MOVEABLEOBJECT_ON");
|
||||||
|
if (stone.HasProperty("_MoveableObject")) stone.SetFloat("_MoveableObject", 1f);
|
||||||
|
stone.SetTexture("_EmissionMap", glow);
|
||||||
|
stone.EnableKeyword("_EMISSION");
|
||||||
|
stone.SetColor("_EmissionColor", Seam);
|
||||||
|
|
||||||
|
// The table goes whole: its meshes, its damage states, its fragments and its four colliders.
|
||||||
|
for (int i = prefab.transform.childCount - 1; i >= 0; i--)
|
||||||
|
Object.DestroyImmediate(prefab.transform.GetChild(i).gameObject);
|
||||||
|
WearNTear wear = prefab.GetComponent<WearNTear>();
|
||||||
|
if (wear != null)
|
||||||
|
{
|
||||||
|
wear.m_new = null;
|
||||||
|
wear.m_worn = null;
|
||||||
|
wear.m_broken = null;
|
||||||
|
wear.m_fragmentRoots = new GameObject[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
// One still collider, from the ground to the tip, a little inside the faces.
|
||||||
|
GameObject solid = new GameObject("collider") { layer = prefab.layer };
|
||||||
|
solid.transform.SetParent(prefab.transform, false);
|
||||||
|
BoxCollider box = solid.AddComponent<BoxCollider>();
|
||||||
|
box.center = new Vector3(0f, (Lift + Height) / 2f, 0f);
|
||||||
|
box.size = new Vector3(HalfBase * 1.4f, Lift + Height, HalfBase * 1.4f);
|
||||||
|
|
||||||
|
Transform floating = new GameObject("float").transform;
|
||||||
|
floating.SetParent(prefab.transform, false);
|
||||||
|
floating.gameObject.layer = prefab.layer;
|
||||||
|
|
||||||
|
MeshRenderer pyramid = Part(floating, "pyramid", PyramidMesh(), stone).GetComponent<MeshRenderer>();
|
||||||
|
|
||||||
|
NexusLook look = prefab.AddComponent<NexusLook>();
|
||||||
|
look.Float = floating;
|
||||||
|
look.SeamRenderer = pyramid;
|
||||||
|
look.Motes = AddMotes(prefab.transform);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static GameObject Part(Transform parent, string name, Mesh mesh, Material material)
|
||||||
|
{
|
||||||
|
GameObject part = new GameObject(name) { layer = parent.gameObject.layer };
|
||||||
|
part.transform.SetParent(parent, false);
|
||||||
|
part.AddComponent<MeshFilter>().sharedMesh = mesh;
|
||||||
|
part.AddComponent<MeshRenderer>().sharedMaterial = material;
|
||||||
|
return part;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Vector3 Apex => new Vector3(0f, Lift + Height, 0f);
|
||||||
|
|
||||||
|
private static Vector3[] BaseCorners => new[]
|
||||||
|
{
|
||||||
|
new Vector3(-HalfBase, Lift, -HalfBase), new Vector3(HalfBase, Lift, -HalfBase),
|
||||||
|
new Vector3(HalfBase, Lift, HalfBase), new Vector3(-HalfBase, Lift, HalfBase),
|
||||||
|
};
|
||||||
|
|
||||||
|
/// <summary>Four faces, each with its own three corners so the shading stays flat and every face
|
||||||
|
/// shows the whole carving (u along the base, v = 1 at the tip), and the underside.</summary>
|
||||||
|
private static Mesh PyramidMesh()
|
||||||
|
{
|
||||||
|
Vector3[] c = BaseCorners;
|
||||||
|
var vertices = new Vector3[16];
|
||||||
|
var uvs = new Vector2[16];
|
||||||
|
var triangles = new int[18];
|
||||||
|
for (int i = 0; i < 4; i++)
|
||||||
|
{
|
||||||
|
// Wound clockwise seen from outside, which is Unity's front face.
|
||||||
|
vertices[i * 3] = c[(i + 1) % 4];
|
||||||
|
vertices[i * 3 + 1] = c[i];
|
||||||
|
vertices[i * 3 + 2] = Apex;
|
||||||
|
uvs[i * 3] = new Vector2(1f, 0f);
|
||||||
|
uvs[i * 3 + 1] = new Vector2(0f, 0f);
|
||||||
|
uvs[i * 3 + 2] = new Vector2(0.5f, 1f);
|
||||||
|
triangles[i * 3] = i * 3;
|
||||||
|
triangles[i * 3 + 1] = i * 3 + 1;
|
||||||
|
triangles[i * 3 + 2] = i * 3 + 2;
|
||||||
|
}
|
||||||
|
for (int i = 0; i < 4; i++) { vertices[12 + i] = c[i]; uvs[12 + i] = new Vector2(0.1f, 0.02f); }
|
||||||
|
int[] under = { 12, 13, 14, 12, 14, 15 };
|
||||||
|
System.Array.Copy(under, 0, triangles, 12, 6);
|
||||||
|
|
||||||
|
Mesh mesh = new Mesh { name = "AlfarNexus_pyramid", vertices = vertices, uv = uvs, triangles = triangles };
|
||||||
|
mesh.RecalculateNormals();
|
||||||
|
mesh.RecalculateBounds();
|
||||||
|
return mesh;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>A few cyan motes drifting up from the ground under it: the torch's embers, recoloured,
|
||||||
|
/// spread over the pyramid's shadow and slowed down.</summary>
|
||||||
|
private static ParticleSystem AddMotes(Transform root)
|
||||||
|
{
|
||||||
|
GameObject torch = PrefabManager.Cache.GetPrefab<GameObject>(EmbersSource);
|
||||||
|
Transform source = torch != null ? torch.transform.Find("Embers") : null;
|
||||||
|
if (source == null) return null;
|
||||||
|
|
||||||
|
GameObject motes = Object.Instantiate(source.gameObject, root, false);
|
||||||
|
motes.name = "motes";
|
||||||
|
motes.transform.localPosition = new Vector3(0f, 0.05f, 0f);
|
||||||
|
motes.transform.localRotation = Quaternion.identity;
|
||||||
|
PieceLook.Rehue(motes.transform, Seam * 2f);
|
||||||
|
|
||||||
|
ParticleSystem particles = motes.GetComponent<ParticleSystem>();
|
||||||
|
if (particles != null)
|
||||||
|
{
|
||||||
|
ParticleSystem.ShapeModule shape = particles.shape;
|
||||||
|
shape.enabled = true;
|
||||||
|
shape.shapeType = ParticleSystemShapeType.Circle;
|
||||||
|
shape.radius = HalfBase;
|
||||||
|
shape.rotation = new Vector3(-90f, 0f, 0f);
|
||||||
|
ParticleSystem.MainModule main = particles.main;
|
||||||
|
main.simulationSpeed = 0.5f;
|
||||||
|
}
|
||||||
|
return particles;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>The motion and the seam's light, per client.</summary>
|
||||||
|
public class NexusLook : MonoBehaviour
|
||||||
|
{
|
||||||
|
public Transform Float;
|
||||||
|
public Renderer SeamRenderer;
|
||||||
|
public ParticleSystem Motes;
|
||||||
|
|
||||||
|
private const float BobHeight = 0.08f;
|
||||||
|
private const float BobSeconds = 4.5f;
|
||||||
|
private const float TurnSeconds = 40f;
|
||||||
|
private const float BreathSeconds = 3.5f;
|
||||||
|
|
||||||
|
private AlfarNexusBehaviour m_nexus;
|
||||||
|
private Material m_seam;
|
||||||
|
private float m_phase;
|
||||||
|
private float m_ready; // eases between 0 (no crystals) and 1, so the brightening is not a jump
|
||||||
|
|
||||||
|
private void Awake()
|
||||||
|
{
|
||||||
|
m_nexus = GetComponent<AlfarNexusBehaviour>();
|
||||||
|
if (SeamRenderer != null) m_seam = SeamRenderer.material; // this one's own copy, to animate
|
||||||
|
// Two Nexuses side by side must not bob in step.
|
||||||
|
m_phase = (Mathf.Abs(transform.position.x * 0.37f + transform.position.z * 0.71f)) % 10f;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Update()
|
||||||
|
{
|
||||||
|
float t = Time.time + m_phase;
|
||||||
|
if (Float != null)
|
||||||
|
{
|
||||||
|
Float.localPosition = new Vector3(0f, Mathf.Sin(t * 2f * Mathf.PI / BobSeconds) * BobHeight, 0f);
|
||||||
|
Float.localRotation = Quaternion.Euler(0f, t * 360f / TurnSeconds, 0f);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m_seam == null) return;
|
||||||
|
bool ready = m_nexus != null && m_nexus.Crystals > 0;
|
||||||
|
m_ready = Mathf.MoveTowards(m_ready, ready ? 1f : 0f, Time.deltaTime * 0.5f);
|
||||||
|
float breath = 0.75f + 0.25f * Mathf.Sin(t * 2f * Mathf.PI / BreathSeconds);
|
||||||
|
Color glow = Seam * breath * Mathf.Lerp(1f, 2.2f, m_ready);
|
||||||
|
m_seam.SetColor("_EmissionColor", glow);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnDestroy()
|
||||||
|
{
|
||||||
|
if (m_seam != null) Destroy(m_seam);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -38,6 +38,37 @@ namespace RacesOfValheim
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Hair and beard never attach to an Alfr. Every equipment change makes the game write the
|
||||||
|
/// profile's hair back (Humanoid.SetupVisEquipment), and ApplyHairless only clears it on its
|
||||||
|
/// 0.5s pass, so players saw the hair flash in for a moment. Zeroing the hash here, where
|
||||||
|
/// VisEquipment spawns the model, means it never appears. Covers remote players too, since
|
||||||
|
/// their visuals go through the same call.
|
||||||
|
/// </summary>
|
||||||
|
[HarmonyPatch(typeof(VisEquipment), "SetHairEquipped")]
|
||||||
|
public static class Alfar_SetHairEquipped_Patch
|
||||||
|
{
|
||||||
|
public static void Prefix(VisEquipment __instance, ref int hash)
|
||||||
|
{
|
||||||
|
if (hash != 0 && IsAlfarVis(__instance)) hash = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[HarmonyPatch(typeof(VisEquipment), "SetBeardEquipped")]
|
||||||
|
public static class Alfar_SetBeardEquipped_Patch
|
||||||
|
{
|
||||||
|
public static void Prefix(VisEquipment __instance, ref int hash)
|
||||||
|
{
|
||||||
|
if (hash != 0 && IsAlfarVis(__instance)) hash = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static bool IsAlfarVis(VisEquipment vis)
|
||||||
|
{
|
||||||
|
Player player = vis.GetComponent<Player>();
|
||||||
|
return player != null && AlfarVisuals.IsAlfarPlayer(player);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The character preview on the main menu is a Player too, with the saved race in its custom data
|
/// The character preview on the main menu is a Player too, with the saved race in its custom data
|
||||||
/// and no ZNetView. Its Update may never run, so a small driver on it keeps the look: skin, hair,
|
/// and no ZNetView. Its Update may never run, so a small driver on it keeps the look: skin, hair,
|
||||||
|
|
|
||||||
|
|
@ -148,12 +148,17 @@ namespace RacesOfValheim
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>A pulse of lightning on every hostile creature within a radius of the Alfr.</summary>
|
/// <summary>A pulse of lightning on every hostile creature within a radius of the Alfr.</summary>
|
||||||
public static void Pulse(Player player, float radius, float damage)
|
/// <returns>True if it struck at least one creature.</returns>
|
||||||
|
public static bool Pulse(Player player, float radius, float damage)
|
||||||
{
|
{
|
||||||
|
bool struck = false;
|
||||||
foreach (Character character in CharactersIn(player.transform.position, radius))
|
foreach (Character character in CharactersIn(player.transform.position, radius))
|
||||||
{
|
{
|
||||||
if (IsHostile(player, character)) Strike(player, character, damage, character.GetCenterPoint());
|
if (!IsHostile(player, character)) continue;
|
||||||
|
Strike(player, character, damage, character.GetCenterPoint());
|
||||||
|
struck = true;
|
||||||
}
|
}
|
||||||
|
return struck;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static IEnumerable<Character> CharactersIn(Vector3 center, float radius)
|
private static IEnumerable<Character> CharactersIn(Vector3 center, float radius)
|
||||||
|
|
@ -177,35 +182,64 @@ namespace RacesOfValheim
|
||||||
Vector3 direction = aim.forward;
|
Vector3 direction = aim.forward;
|
||||||
float distance = AlfarPowerConfig.SkridDistance.Value;
|
float distance = AlfarPowerConfig.SkridDistance.Value;
|
||||||
|
|
||||||
if (!Pay(player, AlfarPowerConfig.SkridCost.Value)) return;
|
|
||||||
|
|
||||||
// Stop short of whatever is in the way, so the blink never ends inside a wall.
|
// Stop short of whatever is in the way, so the blink never ends inside a wall.
|
||||||
Vector3 destination = origin + direction * distance;
|
Vector3 destination = origin + direction * distance;
|
||||||
RaycastHit[] hits = Physics.RaycastAll(origin, direction, distance, ~0, QueryTriggerInteraction.Ignore);
|
if (NearestHit(player, origin, direction, distance, out RaycastHit wall))
|
||||||
float nearest = float.MaxValue;
|
|
||||||
foreach (RaycastHit hit in hits)
|
|
||||||
{
|
{
|
||||||
if (hit.collider.GetComponentInParent<Player>() == player) continue;
|
destination = wall.point - direction * 0.6f;
|
||||||
if (hit.distance < nearest)
|
}
|
||||||
|
|
||||||
|
// Back down to the player's own height: the origin was at the chest. The floor is found
|
||||||
|
// with a short ray down from the landing point, never with GetSolidHeight: that one casts
|
||||||
|
// from 1000 m up, so under any roof (a crypt, a cave, a house) it returned the roof and
|
||||||
|
// put the Alfr on top of it. A flat 1 m drop also sank the feet under the floor when the
|
||||||
|
// blink was aimed at it.
|
||||||
|
const float FloorSearch = 3f;
|
||||||
|
if (NearestHit(player, destination, Vector3.down, FloorSearch, out RaycastHit floor))
|
||||||
|
{
|
||||||
|
destination.y = floor.point.y + 0.05f;
|
||||||
|
}
|
||||||
|
else if (player.InInterior())
|
||||||
|
{
|
||||||
|
// No floor under the landing point inside a dungeon: it would end in the void the
|
||||||
|
// dungeon floats in. Cancel before paying.
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
destination.y -= 1.0f;
|
||||||
|
if (ZoneSystem.instance != null)
|
||||||
{
|
{
|
||||||
nearest = hit.distance;
|
// Terrain only, so a roof overhead is never mistaken for the ground.
|
||||||
destination = hit.point - direction * 0.6f;
|
float ground = ZoneSystem.instance.GetGroundHeight(destination);
|
||||||
|
if (destination.y < ground) destination.y = ground + 0.1f;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Back down to the player's own height: the origin was at the chest.
|
if (!Pay(player, AlfarPowerConfig.SkridCost.Value)) return;
|
||||||
destination.y -= 1.0f;
|
|
||||||
if (ZoneSystem.instance != null)
|
|
||||||
{
|
|
||||||
float ground = ZoneSystem.instance.GetSolidHeight(destination);
|
|
||||||
if (destination.y < ground) destination.y = ground + 0.1f;
|
|
||||||
}
|
|
||||||
|
|
||||||
Teleport(player, destination);
|
Teleport(player, destination);
|
||||||
StartCooldown("skrid", AlfarPowerConfig.SkridCooldown.Value);
|
StartCooldown("skrid", AlfarPowerConfig.SkridCooldown.Value);
|
||||||
AlfarFx.Spawn("fx_JotunWitch_LightningBolt_Explosion", origin);
|
AlfarFx.Spawn("fx_JotunWitch_LightningBolt_Explosion", origin);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>The nearest solid hit along a ray, skipping the caster's own colliders.</summary>
|
||||||
|
private static bool NearestHit(Player player, Vector3 origin, Vector3 direction, float distance, out RaycastHit nearest)
|
||||||
|
{
|
||||||
|
nearest = default;
|
||||||
|
bool found = false;
|
||||||
|
foreach (RaycastHit hit in Physics.RaycastAll(origin, direction, distance, ~0, QueryTriggerInteraction.Ignore))
|
||||||
|
{
|
||||||
|
if (hit.collider.GetComponentInParent<Player>() == player) continue;
|
||||||
|
if (!found || hit.distance < nearest.distance)
|
||||||
|
{
|
||||||
|
nearest = hit;
|
||||||
|
found = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return found;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Moves the body without the teleport fade: the rigidbody is repositioned and its velocity
|
/// Moves the body without the teleport fade: the rigidbody is repositioned and its velocity
|
||||||
/// zeroed, and the fall tracker is reset so a blink up a cliff does not count as a fall.
|
/// zeroed, and the fall tracker is reset so a blink up a cliff does not count as a fall.
|
||||||
|
|
@ -305,6 +339,34 @@ namespace RacesOfValheim
|
||||||
|
|
||||||
// ─── Geisli: the beam ────────────────────────────────────────────────
|
// ─── Geisli: the beam ────────────────────────────────────────────────
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The pad's way to hold the beam. Every pad button is taken in vanilla's Classic layout, so,
|
||||||
|
/// like Skadi's Cold Spell, the beam borrows the secondary attack: bare-handed, or in the
|
||||||
|
/// archon form, which has no weapons anyway. The radial entry only gives a single press,
|
||||||
|
/// which cannot hold a beam.
|
||||||
|
/// </summary>
|
||||||
|
private static bool PadBeamHeld(Player player) =>
|
||||||
|
!RaceInput.RadialOpen && RaceInput.PadAttackHeld(2) &&
|
||||||
|
(AlfarArchon.Active || RaceInput.EmptyHanded(player));
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Swallows the unarmed secondary (the kick) while the pad's secondary attack is the beam,
|
||||||
|
/// the same way SkadiAttackPatch does for the Cold Spell.
|
||||||
|
/// </summary>
|
||||||
|
[HarmonyPatch(typeof(Humanoid), "StartAttack")]
|
||||||
|
public static class Alfar_GeisliPadKick_Patch
|
||||||
|
{
|
||||||
|
public static bool Prefix(Humanoid __instance, bool secondaryAttack, ref bool __result)
|
||||||
|
{
|
||||||
|
if (!secondaryAttack || __instance != Player.m_localPlayer) return true;
|
||||||
|
Player player = (Player)__instance;
|
||||||
|
if (!AlfarVisuals.IsAlfarPlayer(player) || !Unlocked(AlfarPowerConfig.GeisliState)) return true;
|
||||||
|
if (!PadBeamHeld(player)) return true;
|
||||||
|
__result = false;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static LineRenderer beamLine;
|
private static LineRenderer beamLine;
|
||||||
private static readonly List<LineRenderer> beamArcs = new List<LineRenderer>();
|
private static readonly List<LineRenderer> beamArcs = new List<LineRenderer>();
|
||||||
private static GameObject beamFx;
|
private static GameObject beamFx;
|
||||||
|
|
@ -324,7 +386,7 @@ namespace RacesOfValheim
|
||||||
private static void TickBeam(Player player)
|
private static void TickBeam(Player player)
|
||||||
{
|
{
|
||||||
bool wanted = RaceInput.Allowed && !player.IsDead() && Unlocked(AlfarPowerConfig.GeisliState) &&
|
bool wanted = RaceInput.Allowed && !player.IsDead() && Unlocked(AlfarPowerConfig.GeisliState) &&
|
||||||
AlfarPowerConfig.GeisliKey.Value.IsPressedIgnoringHeldKeys();
|
(AlfarPowerConfig.GeisliKey.Value.IsPressedIgnoringHeldKeys() || PadBeamHeld(player));
|
||||||
|
|
||||||
if (!wanted)
|
if (!wanted)
|
||||||
{
|
{
|
||||||
|
|
@ -368,7 +430,11 @@ namespace RacesOfValheim
|
||||||
AlfarEitr.Spend(player, cost);
|
AlfarEitr.Spend(player, cost);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (IsHostile(player, target)) Strike(player, target, AlfarPowerConfig.BeamDps.Value * tick, end);
|
if (IsHostile(player, target))
|
||||||
|
{
|
||||||
|
Strike(player, target, AlfarPowerConfig.BeamDps.Value * tick, end);
|
||||||
|
FormMelee.RaiseSkill(Skills.SkillType.ElementalMagic, tick); // a full hit per second on target
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void RaiseHand(Player player)
|
private static void RaiseHand(Player player)
|
||||||
|
|
@ -520,14 +586,19 @@ namespace RacesOfValheim
|
||||||
const float tick = 0.5f;
|
const float tick = 0.5f;
|
||||||
nextTick = Time.time + tick;
|
nextTick = Time.time + tick;
|
||||||
|
|
||||||
|
bool struck = false;
|
||||||
foreach (Collider collider in Physics.OverlapSphere(transform.position, Radius, ~0, QueryTriggerInteraction.Ignore))
|
foreach (Collider collider in Physics.OverlapSphere(transform.position, Radius, ~0, QueryTriggerInteraction.Ignore))
|
||||||
{
|
{
|
||||||
Character character = collider.GetComponentInParent<Character>();
|
Character character = collider.GetComponentInParent<Character>();
|
||||||
if (character == null || character == Owner || character.IsDead() || character.IsTamed()) continue;
|
if (character == null || character == Owner || character.IsDead() || character.IsTamed()) continue;
|
||||||
if (!BaseAI.IsEnemy(Owner, character)) continue;
|
if (!BaseAI.IsEnemy(Owner, character)) continue;
|
||||||
AlfarPowers.Strike(Owner, character, DamagePerSecond * tick, character.GetCenterPoint());
|
AlfarPowers.Strike(Owner, character, DamagePerSecond * tick, character.GetCenterPoint());
|
||||||
|
struck = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Once per tick, not per creature: a full hit per second the storm strikes something.
|
||||||
|
if (struck && Owner == Player.m_localPlayer) FormMelee.RaiseSkill(Skills.SkillType.ElementalMagic, tick);
|
||||||
|
|
||||||
Vector2 offset = Random.insideUnitCircle * Radius;
|
Vector2 offset = Random.insideUnitCircle * Radius;
|
||||||
AlfarFx.Spawn("fx_JotunWitch_LightningBolt_Explosion", transform.position + new Vector3(offset.x, 0f, offset.y));
|
AlfarFx.Spawn("fx_JotunWitch_LightningBolt_Explosion", transform.position + new Vector3(offset.x, 0f, offset.y));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -161,35 +161,67 @@ namespace RacesOfValheim
|
||||||
}
|
}
|
||||||
if (eyes == null) return;
|
if (eyes == null) return;
|
||||||
|
|
||||||
PlaceEyes(headBone, eyes);
|
PlaceEyes(player, eyes);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void PlaceEyes(Transform headBone, Transform holder)
|
/// <summary>
|
||||||
|
/// A grey's eyes: wide black almonds, outer corners raised, wrapping round the sides of the
|
||||||
|
/// face. Each is a sphere squashed to an ellipsoid and turned in the skull's own frame.
|
||||||
|
///
|
||||||
|
/// FIXED HEAD-LOCAL UNITS, never headBone.lossyScale. The Alfar Visual is scaled
|
||||||
|
/// non-uniformly, so the head's lossyScale is only an approximation that changes as the
|
||||||
|
/// head turns; recomputed on the 0.5s cosmetic pass it made the eyes trail the face. The
|
||||||
|
/// face is skinned to the same bone through the same matrices, so a constant local offset
|
||||||
|
/// stays glued to it at any body scale, and PlaceEyes only has to run when the eyes change.
|
||||||
|
/// </summary>
|
||||||
|
private static void PlaceEyes(Player player, Transform holder)
|
||||||
{
|
{
|
||||||
Vector3 lossy = headBone.lossyScale;
|
|
||||||
if (Mathf.Abs(lossy.x) < 0.0001f || Mathf.Abs(lossy.y) < 0.0001f || Mathf.Abs(lossy.z) < 0.0001f) return;
|
|
||||||
|
|
||||||
EyeFrame frame = holder.GetComponent<EyeFrame>();
|
EyeFrame frame = holder.GetComponent<EyeFrame>();
|
||||||
if (frame == null) return;
|
if (frame == null) return;
|
||||||
|
|
||||||
// The Visual is scaled non-uniformly (thinner than tall), so lossyScale has three
|
const float toLocal = PlayerFace.MetresToHeadLocal;
|
||||||
// different components and a single divisor would squash the spheres. Each axis is
|
|
||||||
// divided by its own.
|
|
||||||
Vector3 toLocal = new Vector3(1f / lossy.x, 1f / lossy.y, 1f / lossy.z);
|
|
||||||
float eyeSize = AlfarConfig.EyeSize * AlfarConfig.EyeSizeMultiplier.Value;
|
|
||||||
|
|
||||||
Vector3 baseOffset = frame.LocalForward * AlfarConfig.EyeForward + frame.LocalUp * AlfarConfig.EyeHeight;
|
float height = AlfarConfig.EyeHeight;
|
||||||
|
float separation = AlfarConfig.EyeSeparation;
|
||||||
|
float size = AlfarConfig.EyeSizeMultiplier.Value;
|
||||||
|
PlayerFace.AdjustEyes(player, ref height, ref separation, ref size);
|
||||||
|
|
||||||
|
Quaternion facing = Quaternion.LookRotation(frame.LocalForward, frame.LocalUp);
|
||||||
|
|
||||||
for (int i = 0; i < holder.childCount; i++)
|
for (int i = 0; i < holder.childCount; i++)
|
||||||
{
|
{
|
||||||
Transform eye = holder.GetChild(i);
|
Transform eye = holder.GetChild(i);
|
||||||
|
|
||||||
// Index 0 is offset against the right axis, so it is the model's left eye.
|
// Index 0 is offset against the right axis, so it is the model's left eye. The
|
||||||
|
// slant and the wrap are mirrored so both outer corners go up and back.
|
||||||
float side = i == 0 ? -1f : 1f;
|
float side = i == 0 ? -1f : 1f;
|
||||||
Vector3 offset = baseOffset + frame.LocalRight * (side * AlfarConfig.EyeSeparation);
|
|
||||||
|
|
||||||
eye.localPosition = Vector3.Scale(offset, toLocal);
|
// This eye's hand corrections (RaceEyeTuning).
|
||||||
eye.localScale = Vector3.Scale(Vector3.one * eyeSize, toLocal);
|
float forward = AlfarConfig.EyeForward;
|
||||||
|
float eyeHeight = height;
|
||||||
|
float eyeSeparation = separation;
|
||||||
|
float eyeSize = size;
|
||||||
|
float wrap = AlfarConfig.EyeWrap;
|
||||||
|
float slant = AlfarConfig.EyeSlant;
|
||||||
|
float tilt = 0f;
|
||||||
|
RaceEyeTuning.Eye tuning = RaceEyeTuning.For(AlfarConfig.RaceId, player, side);
|
||||||
|
if (tuning != null)
|
||||||
|
{
|
||||||
|
forward += tuning.Forward;
|
||||||
|
eyeHeight += tuning.Height;
|
||||||
|
eyeSeparation += tuning.Separation;
|
||||||
|
eyeSize *= tuning.Size;
|
||||||
|
tilt = tuning.RotX;
|
||||||
|
wrap += tuning.RotY;
|
||||||
|
slant += tuning.RotZ;
|
||||||
|
}
|
||||||
|
|
||||||
|
Vector3 offset = frame.LocalForward * forward + frame.LocalUp * eyeHeight
|
||||||
|
+ frame.LocalRight * (side * eyeSeparation);
|
||||||
|
|
||||||
|
eye.localPosition = offset * toLocal;
|
||||||
|
eye.localRotation = facing * Quaternion.Euler(tilt, wrap * side, slant * side);
|
||||||
|
eye.localScale = AlfarConfig.EyeExtent * (eyeSize * toLocal);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -234,9 +266,8 @@ namespace RacesOfValheim
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Matte black, and nothing else: the colour is black, the emission is black, and the two
|
/// Black with a wet sheen: no emission, but smooth enough to catch a highlight, which is
|
||||||
/// properties that make a lit shader shine are zeroed where the shader has them. The
|
/// what makes a grey's eyes read as eyes and not as two holes punched in the face.
|
||||||
/// Sverm's eyes burn; these must read as holes.
|
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private static Material BlackMaterial(Shader shader)
|
private static Material BlackMaterial(Shader shader)
|
||||||
{
|
{
|
||||||
|
|
@ -244,10 +275,9 @@ namespace RacesOfValheim
|
||||||
material.color = Color.black;
|
material.color = Color.black;
|
||||||
|
|
||||||
if (material.HasProperty("_EmissionColor")) material.SetColor("_EmissionColor", Color.black);
|
if (material.HasProperty("_EmissionColor")) material.SetColor("_EmissionColor", Color.black);
|
||||||
if (material.HasProperty("_Glossiness")) material.SetFloat("_Glossiness", 0f);
|
if (material.HasProperty("_Glossiness")) material.SetFloat("_Glossiness", 0.8f);
|
||||||
if (material.HasProperty("_Smoothness")) material.SetFloat("_Smoothness", 0f);
|
if (material.HasProperty("_Smoothness")) material.SetFloat("_Smoothness", 0.8f);
|
||||||
if (material.HasProperty("_Metallic")) material.SetFloat("_Metallic", 0f);
|
if (material.HasProperty("_Metallic")) material.SetFloat("_Metallic", 0f);
|
||||||
if (material.HasProperty("_SpecColor")) material.SetColor("_SpecColor", Color.black);
|
|
||||||
|
|
||||||
return material;
|
return material;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
BIN
JotunnModStub/Assets/AlfarFireChest/AlfarFireChest_d.png
Normal file
|
After Width: | Height: | Size: 53 KiB |
BIN
JotunnModStub/Assets/AlfarFireChest/AlfarFireChest_icon.png
Normal file
|
After Width: | Height: | Size: 9.5 KiB |
BIN
JotunnModStub/Assets/AlfarInputChest/AlfarInputChest_d.png
Normal file
|
After Width: | Height: | Size: 8.1 KiB |
BIN
JotunnModStub/Assets/AlfarInputChest/AlfarInputChest_icon.png
Normal file
|
After Width: | Height: | Size: 9.7 KiB |
BIN
JotunnModStub/Assets/AlfarNexus/AlfarNexus_face.png
Normal file
|
After Width: | Height: | Size: 216 KiB |
BIN
JotunnModStub/Assets/AlfarNexus/AlfarNexus_glow.png
Normal file
|
After Width: | Height: | Size: 1.9 KiB |
BIN
JotunnModStub/Assets/AlfarNexus/AlfarNexus_icon.png
Normal file
|
After Width: | Height: | Size: 11 KiB |
BIN
JotunnModStub/Assets/AlfarNexus/AlfarNexus_n.png
Normal file
|
After Width: | Height: | Size: 259 KiB |
BIN
JotunnModStub/Assets/CookCloth/CookCloth_d.png
Normal file
|
After Width: | Height: | Size: 65 KiB |
BIN
JotunnModStub/Assets/CookCloth/CookCloth_n.png
Normal file
|
After Width: | Height: | Size: 100 KiB |
BIN
JotunnModStub/Assets/CookCloth/CookCloth_worn_d.png
Normal file
|
After Width: | Height: | Size: 72 KiB |
BIN
JotunnModStub/Assets/Hammers/ShrinkHammer_icon.png
Normal file
|
After Width: | Height: | Size: 14 KiB |
BIN
JotunnModStub/Assets/Hammers/TrolsHammer_icon.png
Normal file
|
After Width: | Height: | Size: 19 KiB |
BIN
JotunnModStub/Assets/SmithMail/SmithMail_d.png
Normal file
|
After Width: | Height: | Size: 340 KiB |
BIN
JotunnModStub/Assets/SmithMail/SmithMail_m.png
Normal file
|
After Width: | Height: | Size: 18 KiB |
BIN
JotunnModStub/Assets/SmithMail/SmithMail_n.png
Normal file
|
After Width: | Height: | Size: 441 KiB |
BIN
JotunnModStub/Assets/SmithMail/SmithMail_worn_d.png
Normal file
|
After Width: | Height: | Size: 339 KiB |
|
|
@ -1,182 +0,0 @@
|
||||||
using HarmonyLib;
|
|
||||||
using UnityEngine;
|
|
||||||
|
|
||||||
namespace RacesOfValheim
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Why nothing in Valheim ever attacked the bat, and the smallest honest fix for it.
|
|
||||||
///
|
|
||||||
/// The bat flies on Player.m_debugFly - the developer no-clip flag - because that is the only
|
|
||||||
/// flight vanilla actually has, and it is what BatFormBehavior sets and WarVultureMount reuses.
|
|
||||||
/// What nobody noticed is that vanilla reads that same flag as "this player is not really
|
|
||||||
/// here". Six places, all read out of assembly_valheim with Cecil rather than guessed:
|
|
||||||
///
|
|
||||||
/// BaseAI.CanHearTarget - first line: the target is a Player in debug fly -> return false.
|
|
||||||
/// BaseAI.CanSeeTarget - the same first line, the same false.
|
|
||||||
/// BaseAI.FindEnemy - its HuntPlayer fallback throws the player away for the same reason.
|
|
||||||
/// MonsterAI.UpdateSleep - a sleeping monster refuses to wake for one, twice over.
|
|
||||||
/// Character.ApplyDamage - first line: IsDebugFlying -> return, the hit does nothing.
|
|
||||||
/// Character.RPC_Damage - the same.
|
|
||||||
///
|
|
||||||
/// So the bat was never merely ignored: it was invulnerable as well, and both facts came out of
|
|
||||||
/// the one flag. There was nothing wrong with the Aswid's own code, which is why nothing in it
|
|
||||||
/// looked wrong.
|
|
||||||
///
|
|
||||||
/// The fix keeps the flag - it IS the flight - and lies about it in exactly the places that
|
|
||||||
/// decide aggro and damage, and nowhere else:
|
|
||||||
///
|
|
||||||
/// Player.InDebugFlyMode() is forced false for a bat unconditionally. That is safe, and it is
|
|
||||||
/// the reason this file is short: a scan of the whole assembly says that method has
|
|
||||||
/// exactly three callers, and all three are the sensing paths listed above. No part of
|
|
||||||
/// flight, camera, stamina or motion goes through it.
|
|
||||||
/// Player.IsDebugFlying() is NOT forced false, because Character.UpdateMotion reads it and
|
|
||||||
/// that read is what holds the bat in the air. It is only forced false while the call
|
|
||||||
/// stack is inside one of the three vanilla methods that must not honour it, which is
|
|
||||||
/// what the depth counter below is for.
|
|
||||||
///
|
|
||||||
/// Both halves sit behind their own config toggle, so a bat can be made visible-but-immortal,
|
|
||||||
/// or put back the way it was, without touching code.
|
|
||||||
/// </summary>
|
|
||||||
public static class AswidBatForm
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// The ZDO flag AswidRace writes when the form goes up. Replicated, so it answers for
|
|
||||||
/// remote players too - which matters here, because the machine asking "is this player a
|
|
||||||
/// bat" is whichever one owns the monster, not the bat's own.
|
|
||||||
/// </summary>
|
|
||||||
public const string BatZdoKey = "Aswid_IsBatForm";
|
|
||||||
|
|
||||||
private static readonly int BatFormHash = "SE_BatForm".GetStableHashCode();
|
|
||||||
|
|
||||||
// How deep we currently are inside vanilla calls that must not see the debug-fly flag. A
|
|
||||||
// counter and not a bool: ApplyDamage runs inside RPC_Damage, so the frames nest.
|
|
||||||
private static int unmaskDepth;
|
|
||||||
|
|
||||||
public static bool Unmasked => unmaskDepth > 0;
|
|
||||||
public static void PushUnmask() { unmaskDepth++; }
|
|
||||||
public static void PopUnmask() { if (unmaskDepth > 0) unmaskDepth--; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The ZDO first and the status effect only as a fallback: the ZDO is the one that is true
|
|
||||||
/// on every client, and the status effect covers the local player during the frames of the
|
|
||||||
/// transform where the ZDO write has not landed yet.
|
|
||||||
/// </summary>
|
|
||||||
public static bool IsBat(Player player)
|
|
||||||
{
|
|
||||||
if (player == null) return false;
|
|
||||||
|
|
||||||
ZNetView nview = player.GetComponent<ZNetView>();
|
|
||||||
if (nview != null && nview.IsValid() && nview.GetZDO().GetBool(BatZdoKey, false)) return true;
|
|
||||||
|
|
||||||
return player == Player.m_localPlayer &&
|
|
||||||
player.GetSEMan() != null &&
|
|
||||||
player.GetSEMan().HaveStatusEffect(BatFormHash);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The whole of the aggro fix. See AswidBatForm for why patching this one method flat is safe,
|
|
||||||
/// and why patching IsDebugFlying flat would drop the bat out of the sky instead.
|
|
||||||
/// </summary>
|
|
||||||
[HarmonyPatch(typeof(Player), "InDebugFlyMode")]
|
|
||||||
public static class Aswid_BatIsVisibleToAI_Patch
|
|
||||||
{
|
|
||||||
public static void Postfix(Player __instance, ref bool __result)
|
|
||||||
{
|
|
||||||
if (!__result) return;
|
|
||||||
if (AswidConfig.BatFormAggro != null && !AswidConfig.BatFormAggro.Value) return;
|
|
||||||
if (AswidBatForm.IsBat(__instance)) __result = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The scoped half. Only ever fires inside the three vanilla methods that push the counter, and
|
|
||||||
/// only for a player who is a bat - so the flag still reads true everywhere flight, motion, the
|
|
||||||
/// camera and Player.UpdateStats look at it.
|
|
||||||
/// </summary>
|
|
||||||
[HarmonyPatch(typeof(Player), "IsDebugFlying")]
|
|
||||||
public static class Aswid_BatIsDebugFlying_Patch
|
|
||||||
{
|
|
||||||
public static void Postfix(Player __instance, ref bool __result)
|
|
||||||
{
|
|
||||||
if (!__result || !AswidBatForm.Unmasked) return;
|
|
||||||
if (AswidBatForm.IsBat(__instance)) __result = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// A hit landing on a bat. Finalizer rather than Postfix throughout this file: the counter has
|
|
||||||
/// to come back down even when the patched method throws, and a Postfix does not run then. A
|
|
||||||
/// void Finalizer leaves the original exception alone, so nothing is swallowed either.
|
|
||||||
/// </summary>
|
|
||||||
[HarmonyPatch(typeof(Character), "ApplyDamage")]
|
|
||||||
public static class Aswid_BatTakesDamage_Patch
|
|
||||||
{
|
|
||||||
public static void Prefix(Character __instance, ref bool __state)
|
|
||||||
{
|
|
||||||
__state = (AswidConfig.BatFormVulnerable == null || AswidConfig.BatFormVulnerable.Value)
|
|
||||||
&& __instance is Player player && AswidBatForm.IsBat(player);
|
|
||||||
if (__state) AswidBatForm.PushUnmask();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void Finalizer(bool __state)
|
|
||||||
{
|
|
||||||
if (__state) AswidBatForm.PopUnmask();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>The networked half of the same thing: a hit sent by another machine.</summary>
|
|
||||||
[HarmonyPatch(typeof(Character), "RPC_Damage")]
|
|
||||||
public static class Aswid_BatTakesRemoteDamage_Patch
|
|
||||||
{
|
|
||||||
public static void Prefix(Character __instance, ref bool __state)
|
|
||||||
{
|
|
||||||
__state = (AswidConfig.BatFormVulnerable == null || AswidConfig.BatFormVulnerable.Value)
|
|
||||||
&& __instance is Player player && AswidBatForm.IsBat(player);
|
|
||||||
if (__state) AswidBatForm.PushUnmask();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void Finalizer(bool __state)
|
|
||||||
{
|
|
||||||
if (__state) AswidBatForm.PopUnmask();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Sleepers. Unlike the two above this cannot pre-check who the player is - UpdateSleep picks
|
|
||||||
/// the closest one itself, and that may be a remote bat - so the counter goes up for the whole
|
|
||||||
/// call and the per-player test happens in the IsDebugFlying postfix, where it costs nothing:
|
|
||||||
/// that postfix only runs at all for a character who is already flying.
|
|
||||||
/// </summary>
|
|
||||||
[HarmonyPatch(typeof(MonsterAI), "UpdateSleep")]
|
|
||||||
public static class Aswid_BatWakesSleepers_Patch
|
|
||||||
{
|
|
||||||
public static void Prefix(ref bool __state)
|
|
||||||
{
|
|
||||||
__state = AswidConfig.BatFormAggro == null || AswidConfig.BatFormAggro.Value;
|
|
||||||
if (__state) AswidBatForm.PushUnmask();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void Finalizer(bool __state)
|
|
||||||
{
|
|
||||||
if (__state) AswidBatForm.PopUnmask();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Dying as a bat only became possible with the patches above, and the revert path could not
|
|
||||||
/// handle it: AswidRace.Update() returns early on IsDead(), so the coroutine that takes the
|
|
||||||
/// form down never starts. The debug-fly flag would stay on and the ZDO would stay true, which
|
|
||||||
/// is a respawned player floating over the ground with a bat drawn on them.
|
|
||||||
/// </summary>
|
|
||||||
[HarmonyPatch(typeof(Player), "OnDeath")]
|
|
||||||
public static class Aswid_BatDiesAsBat_Patch
|
|
||||||
{
|
|
||||||
public static void Prefix(Player __instance)
|
|
||||||
{
|
|
||||||
if (__instance != Player.m_localPlayer) return;
|
|
||||||
if (AswidRace.Instance == null) return;
|
|
||||||
AswidRace.Instance.HardResetBatForm();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,57 +0,0 @@
|
||||||
using HarmonyLib;
|
|
||||||
using UnityEngine;
|
|
||||||
|
|
||||||
namespace RacesOfValheim
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// How fast the bat flies, as a factor on vanilla's own debug-fly speed.
|
|
||||||
///
|
|
||||||
/// The form flies on Player.m_debugFly (see AswidBatForm for why), so its speed is whatever
|
|
||||||
/// Character.UpdateDebugFly decides. Read out of assembly_valheim rather than assumed, that
|
|
||||||
/// method ends with:
|
|
||||||
///
|
|
||||||
/// m_currentVel = Vector3.Lerp(m_currentVel, b, 0.5f);
|
|
||||||
/// m_body.linearVelocity = m_currentVel;
|
|
||||||
///
|
|
||||||
/// where b is m_moveDir times m_debugFlySpeed - a public STATIC INT, 20 by default, times 2.5
|
|
||||||
/// while the run key is held.
|
|
||||||
///
|
|
||||||
/// Two ways to make that faster were rejected before this one:
|
|
||||||
///
|
|
||||||
/// Retuning m_debugFlySpeed around the call. It is shared by every character in the game and
|
|
||||||
/// it is an int, so a 1.35x multiplier would land on 27 and a 1.37x on the same 27 - the
|
|
||||||
/// slider would move in 5% steps and would be writing a global while it did it.
|
|
||||||
///
|
|
||||||
/// Scaling m_currentVel itself, which is what WarVultureMount does for the bird. That field
|
|
||||||
/// is the input to the NEXT frame's lerp, so scaling it feeds back: with a factor s the
|
|
||||||
/// velocity settles at 0.5s/(1-0.5s) times vanilla, not s times it, and at s >= 2 it does
|
|
||||||
/// not settle at all.
|
|
||||||
///
|
|
||||||
/// So only the rigidbody is scaled, and m_currentVel is left exactly as vanilla wrote it. The
|
|
||||||
/// lerp keeps smoothing the same trajectory it always did - the ramp up, the ease off, the
|
|
||||||
/// standstill at zero input - and the bat simply covers it faster. Linear in the slider, with
|
|
||||||
/// nothing to accumulate.
|
|
||||||
/// </summary>
|
|
||||||
[HarmonyPatch(typeof(Character), "UpdateDebugFly")]
|
|
||||||
public static class Aswid_BatFlightSpeed_Patch
|
|
||||||
{
|
|
||||||
public static void Postfix(Character __instance, Vector3 ___m_currentVel, Rigidbody ___m_body)
|
|
||||||
{
|
|
||||||
// Bound from RacesOfValheim.Awake(), before harmony.PatchAll() - the null check is for
|
|
||||||
// the config that failed to bind at all, not for a race between the two.
|
|
||||||
if (AswidConfig.BatFormFlightSpeed == null) return;
|
|
||||||
|
|
||||||
float multiplier = AswidConfig.BatFormFlightSpeed.Value;
|
|
||||||
if (Mathf.Approximately(multiplier, 1f)) return;
|
|
||||||
|
|
||||||
// Local player only. Every other machine's bat moves on its replicated position, and
|
|
||||||
// scaling velocity here would fight that sync rather than help it.
|
|
||||||
Player player = __instance as Player;
|
|
||||||
if (player == null || player != Player.m_localPlayer) return;
|
|
||||||
if (___m_body == null) return;
|
|
||||||
if (!AswidBatForm.IsBat(player)) return;
|
|
||||||
|
|
||||||
___m_body.linearVelocity = ___m_currentVel * multiplier;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
170
JotunnModStub/Aswid/AswidBatForm.cs
Normal file
|
|
@ -0,0 +1,170 @@
|
||||||
|
using HarmonyLib;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace RacesOfValheim
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Whether a player is a bat, on any client.
|
||||||
|
///
|
||||||
|
/// Stamina Flight flies on m_flying (DirectedFlight.cs), which vanilla's AI and damage never
|
||||||
|
/// look at, so monsters notice and hurt that bat with no help.
|
||||||
|
///
|
||||||
|
/// Free Flight flies on vanilla's debug-fly flag, and vanilla reads that flag as "this player
|
||||||
|
/// is not really here". Six places, read out of assembly_valheim:
|
||||||
|
///
|
||||||
|
/// BaseAI.CanHearTarget, BaseAI.CanSeeTarget and BaseAI's HuntPlayer fallback ask
|
||||||
|
/// Player.InDebugFlyMode() and drop the player.
|
||||||
|
/// MonsterAI.UpdateSleep asks IsDebugFlying() and will not wake, twice over.
|
||||||
|
/// Character.ApplyDamage and Character.RPC_Damage ask IsDebugFlying() and drop the hit.
|
||||||
|
///
|
||||||
|
/// The patches below keep the flag (it IS the flight) and lie about it in exactly those
|
||||||
|
/// places, for bats only. InDebugFlyMode() is forced false flat: those three AI paths are its
|
||||||
|
/// only callers. IsDebugFlying() cannot be: Character.UpdateMotion reads it to hold the bat in
|
||||||
|
/// the air, so it reads false only while the call stack is inside one of the methods that push
|
||||||
|
/// the counter. The patches were removed with the old flight in v1.6.1 and came back with it.
|
||||||
|
/// </summary>
|
||||||
|
public static class AswidBatForm
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The ZDO flag AswidRace writes when the form goes up. Replicated, so it answers for
|
||||||
|
/// remote players too.
|
||||||
|
/// </summary>
|
||||||
|
public const string BatZdoKey = "Aswid_IsBatForm";
|
||||||
|
|
||||||
|
private static readonly int BatFormHash = "SE_BatForm".GetStableHashCode();
|
||||||
|
|
||||||
|
// How deep we are inside vanilla calls that must not see the debug-fly flag. A counter,
|
||||||
|
// not a bool: ApplyDamage runs inside RPC_Damage, so the frames nest.
|
||||||
|
private static int unmaskDepth;
|
||||||
|
|
||||||
|
public static bool Unmasked => unmaskDepth > 0;
|
||||||
|
public static void PushUnmask() { unmaskDepth++; }
|
||||||
|
public static void PopUnmask() { if (unmaskDepth > 0) unmaskDepth--; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The ZDO first and the status effect only as a fallback: the ZDO is the one that is true
|
||||||
|
/// on every client, and the status effect covers the local player during the frames of the
|
||||||
|
/// transform where the ZDO write has not landed yet.
|
||||||
|
/// </summary>
|
||||||
|
public static bool IsBat(Player player)
|
||||||
|
{
|
||||||
|
if (player == null) return false;
|
||||||
|
|
||||||
|
ZNetView nview = player.GetComponent<ZNetView>();
|
||||||
|
if (nview != null && nview.IsValid() && nview.GetZDO().GetBool(BatZdoKey, false)) return true;
|
||||||
|
|
||||||
|
return player == Player.m_localPlayer &&
|
||||||
|
player.GetSEMan() != null &&
|
||||||
|
player.GetSEMan().HaveStatusEffect(BatFormHash);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>Free Flight: monsters see and hear a bat. See AswidBatForm for why this one is safe flat.</summary>
|
||||||
|
[HarmonyPatch(typeof(Player), "InDebugFlyMode")]
|
||||||
|
public static class Aswid_BatIsVisibleToAI_Patch
|
||||||
|
{
|
||||||
|
public static void Postfix(Player __instance, ref bool __result)
|
||||||
|
{
|
||||||
|
if (__result && AswidBatForm.IsBat(__instance)) __result = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The scoped half: false only inside the methods that push the counter, so flight, motion,
|
||||||
|
/// the camera and UpdateStats still read the flag as true.
|
||||||
|
/// </summary>
|
||||||
|
[HarmonyPatch(typeof(Player), "IsDebugFlying")]
|
||||||
|
public static class Aswid_BatIsDebugFlying_Patch
|
||||||
|
{
|
||||||
|
public static void Postfix(Player __instance, ref bool __result)
|
||||||
|
{
|
||||||
|
if (!__result || !AswidBatForm.Unmasked) return;
|
||||||
|
if (AswidBatForm.IsBat(__instance)) __result = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// A hit landing on a free-flying bat. Finalizer rather than Postfix: the counter has to come
|
||||||
|
/// down even when the method throws, and a void Finalizer leaves the exception alone.
|
||||||
|
/// </summary>
|
||||||
|
[HarmonyPatch(typeof(Character), "ApplyDamage")]
|
||||||
|
public static class Aswid_BatTakesDamage_Patch
|
||||||
|
{
|
||||||
|
public static void Prefix(Character __instance, ref bool __state)
|
||||||
|
{
|
||||||
|
__state = __instance is Player player && AswidBatForm.IsBat(player);
|
||||||
|
if (__state) AswidBatForm.PushUnmask();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void Finalizer(bool __state)
|
||||||
|
{
|
||||||
|
if (__state) AswidBatForm.PopUnmask();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>The networked half of the same thing: a hit sent by another machine.</summary>
|
||||||
|
[HarmonyPatch(typeof(Character), "RPC_Damage")]
|
||||||
|
public static class Aswid_BatTakesRemoteDamage_Patch
|
||||||
|
{
|
||||||
|
public static void Prefix(Character __instance, ref bool __state)
|
||||||
|
{
|
||||||
|
__state = __instance is Player player && AswidBatForm.IsBat(player);
|
||||||
|
if (__state) AswidBatForm.PushUnmask();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void Finalizer(bool __state)
|
||||||
|
{
|
||||||
|
if (__state) AswidBatForm.PopUnmask();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Notes when the local player last lost health, for the bat's combat lock. ApplyDamage is the
|
||||||
|
/// one final stage for direct hits, burning, poison and bleeding, so comparing health around it
|
||||||
|
/// catches them all, and a hit fully blocked or absorbed (Alfar shield, Heimkall) is no hurt.
|
||||||
|
/// </summary>
|
||||||
|
[HarmonyPatch(typeof(Character), "ApplyDamage",
|
||||||
|
new[] { typeof(HitData), typeof(bool), typeof(bool), typeof(HitData.DamageModifier) })]
|
||||||
|
public static class Aswid_BatCombatLock_Patch
|
||||||
|
{
|
||||||
|
public static void Prefix(Character __instance, ref float __state)
|
||||||
|
{
|
||||||
|
__state = __instance == Player.m_localPlayer ? __instance.GetHealth() : -1f;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void Postfix(Character __instance, float __state)
|
||||||
|
{
|
||||||
|
if (__state < 0f) return;
|
||||||
|
if (__instance.GetHealth() < __state) AswidRace.LastHurtTime = Time.time;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Sleepers. UpdateSleep picks the closest player itself, possibly a remote bat, so the counter
|
||||||
|
/// goes up for the whole call and the bat test happens in the IsDebugFlying postfix, which only
|
||||||
|
/// runs its test for a player already debug flying.
|
||||||
|
/// </summary>
|
||||||
|
[HarmonyPatch(typeof(MonsterAI), "UpdateSleep")]
|
||||||
|
public static class Aswid_BatWakesSleepers_Patch
|
||||||
|
{
|
||||||
|
public static void Prefix() { AswidBatForm.PushUnmask(); }
|
||||||
|
public static void Finalizer() { AswidBatForm.PopUnmask(); }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The revert path cannot handle a bat that dies: AswidRace.Update() returns early on IsDead(),
|
||||||
|
/// so the coroutine that takes the form down never starts. The flight flag would stay on and
|
||||||
|
/// the ZDO would stay true, which is a respawned player floating over the ground with a bat
|
||||||
|
/// drawn on them.
|
||||||
|
/// </summary>
|
||||||
|
[HarmonyPatch(typeof(Player), "OnDeath")]
|
||||||
|
public static class Aswid_BatDiesAsBat_Patch
|
||||||
|
{
|
||||||
|
public static void Prefix(Player __instance)
|
||||||
|
{
|
||||||
|
if (__instance != Player.m_localPlayer) return;
|
||||||
|
if (AswidRace.Instance == null) return;
|
||||||
|
AswidRace.Instance.HardResetBatForm();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -338,8 +338,6 @@ namespace RacesOfValheim
|
||||||
// The raw -> cooked table the Draugh already maintains is the source of truth.
|
// The raw -> cooked table the Draugh already maintains is the source of truth.
|
||||||
meatToCooked = new Dictionary<string, string>(DraughFoodPatches.rawToCookedMapping);
|
meatToCooked = new Dictionary<string, string>(DraughFoodPatches.rawToCookedMapping);
|
||||||
meatToCooked.Remove("GreydwarfEye"); // stew ingredient, not flesh
|
meatToCooked.Remove("GreydwarfEye"); // stew ingredient, not flesh
|
||||||
meatToCooked["AsksvinMeat"] = "CookedAsksvinMeat";
|
|
||||||
meatToCooked["BoneMawSerpentMeat"] = "CookedBoneMawSerpentMeat";
|
|
||||||
|
|
||||||
foreach (string stationName in CookingStationPrefabs)
|
foreach (string stationName in CookingStationPrefabs)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -33,13 +33,81 @@ namespace RacesOfValheim
|
||||||
public static ConfigEntry<float> BloodMagicSkillGainMultiplier;
|
public static ConfigEntry<float> BloodMagicSkillGainMultiplier;
|
||||||
public static ConfigEntry<float> SurtlingFormDamageBonus;
|
public static ConfigEntry<float> SurtlingFormDamageBonus;
|
||||||
|
|
||||||
|
// ─── Stamina ─────────────────────────────────────────────────────────────
|
||||||
|
// The race used to have infinite stamina. Now it has a large pool that grows with each
|
||||||
|
// boss, on top of what its devoured food gives - added, never assigned, so stamina mods
|
||||||
|
// still stack.
|
||||||
|
public static ConfigEntry<float> BaseStaminaBonus;
|
||||||
|
public static ConfigEntry<float> StaminaBonusPerState;
|
||||||
|
public static ConfigEntry<float> StaminaCostMultiplier;
|
||||||
|
|
||||||
|
// ─── Weaknesses ──────────────────────────────────────────────────────────
|
||||||
|
// The Discord reports said the race had no real downsides. Each weakness has its own
|
||||||
|
// switch, so a single player can drop one; on a server the host's values win.
|
||||||
|
public static ConfigEntry<bool> SunlightEnabled;
|
||||||
|
public static ConfigEntry<float> SunHealthRegenPenalty;
|
||||||
|
public static ConfigEntry<float> SunStaminaRegenPenalty;
|
||||||
|
public static ConfigEntry<float> SunSpeedPenalty;
|
||||||
|
public static ConfigEntry<float> SunHealthLossPerSecond;
|
||||||
|
public static ConfigEntry<float> SunHealthFloor;
|
||||||
|
public static ConfigEntry<bool> FireWeaknessEnabled;
|
||||||
|
public static ConfigEntry<float> FireWeakness;
|
||||||
|
public static ConfigEntry<bool> FaderRemovesFireWeakness;
|
||||||
|
public static ConfigEntry<bool> PierceWeaknessEnabled;
|
||||||
|
public static ConfigEntry<float> PierceWeakness;
|
||||||
|
|
||||||
|
// ─── Running Water ─────────────────────────────────────────────────────
|
||||||
|
// Lore says a vampire cannot cross running water unaided (Dagaz's report). Swimming costs
|
||||||
|
// more, and open water - sea, river or lake - burns, swimming or flying over it; a boat
|
||||||
|
// carries you, which the lore allows, though the camera still sways on board. The camera sway is a per-player comfort choice and stays local
|
||||||
|
// (ConfigSync's "camera sway" key part).
|
||||||
|
public static ConfigEntry<bool> RunningWaterEnabled;
|
||||||
|
public static ConfigEntry<bool> WaterOceanOnly;
|
||||||
|
public static ConfigEntry<float> SwimStaminaMultiplier;
|
||||||
|
public static ConfigEntry<float> SeaHealthLossPerSecond;
|
||||||
|
public static ConfigEntry<float> SeaStaminaDrainPerSecond;
|
||||||
|
public static ConfigEntry<float> SeaHealthFloor;
|
||||||
|
public static ConfigEntry<bool> SeaCameraSway;
|
||||||
|
public static ConfigEntry<float> SeaCameraSwayStrength;
|
||||||
|
|
||||||
// ─── Bat Form ────────────────────────────────────────────────────────────
|
// ─── Bat Form ────────────────────────────────────────────────────────────
|
||||||
// Both of these undo something vanilla does to any player on the debug-fly flag, which is
|
// The bat flies on the same directed flight as the Skadi's drakes (DirectedFlight.cs),
|
||||||
// what the bat flies on. See AswidBatAggro for the six vanilla methods involved.
|
// with its own numbers. It used to fly on vanilla's debug-fly flag: 50 m/s, free, blind
|
||||||
public static ConfigEntry<bool> BatFormAggro;
|
// to carry weight, and ignored by every monster until AswidBatAggro lied to six vanilla
|
||||||
public static ConfigEntry<bool> BatFormVulnerable;
|
// methods about it. The old flight came back as Free Flight, for players who want it
|
||||||
// A factor on vanilla's debug-fly speed, not a speed in metres - see AswidBatFlight.
|
// (building tall); AswidBatForm holds the aggro patches it needs.
|
||||||
public static ConfigEntry<float> BatFormFlightSpeed;
|
public enum EncumberedMode { Allowed, Blocked }
|
||||||
|
public enum BatFlightRuleMode { PlayerChoice, AlwaysStaminaFlight, AlwaysFreeFlight }
|
||||||
|
|
||||||
|
public static ConfigEntry<bool> FreeBatFlight;
|
||||||
|
public static ConfigEntry<BatFlightRuleMode> BatFlightRule;
|
||||||
|
|
||||||
|
/// <summary>Which flight a bat taken now gets: the server's rule first, then the player's own pick.</summary>
|
||||||
|
public static bool UsesFreeBatFlight()
|
||||||
|
{
|
||||||
|
switch (BatFlightRule.Value)
|
||||||
|
{
|
||||||
|
case BatFlightRuleMode.AlwaysStaminaFlight: return false;
|
||||||
|
case BatFlightRuleMode.AlwaysFreeFlight: return true;
|
||||||
|
default: return FreeBatFlight.Value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ConfigEntry<float> BatTurnSpeed;
|
||||||
|
public static ConfigEntry<float> BatGlideSpeed;
|
||||||
|
public static ConfigEntry<float> BatBoostSpeed;
|
||||||
|
public static ConfigEntry<float> BatSprintSpeed;
|
||||||
|
public static ConfigEntry<float> BatReverseSpeed;
|
||||||
|
public static ConfigEntry<float> BatLiftoffSpeed;
|
||||||
|
public static ConfigEntry<float> BatHoverSeconds;
|
||||||
|
public static ConfigEntry<float> BatPoweredStaminaPerSecond;
|
||||||
|
public static ConfigEntry<float> BatSprintStaminaPerSecond;
|
||||||
|
public static ConfigEntry<EncumberedMode> BatEncumbered;
|
||||||
|
public static ConfigEntry<float> BatEncumberedExtraCost;
|
||||||
|
public static ConfigEntry<float> BatMaxDuration;
|
||||||
|
public static ConfigEntry<float> BatDurationPerState;
|
||||||
|
public static ConfigEntry<float> BatCooldown;
|
||||||
|
public static ConfigEntry<float> BatCombatLock;
|
||||||
|
|
||||||
// ─── Vampiric Aura (passive, always active) ──────────────────────────────
|
// ─── Vampiric Aura (passive, always active) ──────────────────────────────
|
||||||
public static ConfigEntry<float> AuraTickInterval;
|
public static ConfigEntry<float> AuraTickInterval;
|
||||||
|
|
@ -48,6 +116,8 @@ namespace RacesOfValheim
|
||||||
public static ConfigEntry<float> AuraBaseDamage;
|
public static ConfigEntry<float> AuraBaseDamage;
|
||||||
public static ConfigEntry<float> AuraBloodMagicScaling;
|
public static ConfigEntry<float> AuraBloodMagicScaling;
|
||||||
public static ConfigEntry<float> AuraExecuteThreshold;
|
public static ConfigEntry<float> AuraExecuteThreshold;
|
||||||
|
public static ConfigEntry<bool> AuraInBatForm;
|
||||||
|
public static ConfigEntry<int> BatAuraUnlockState;
|
||||||
|
|
||||||
// ─── Superhuman Senses (tier 5+ passive) ─────────────────────────────────
|
// ─── Superhuman Senses (tier 5+ passive) ─────────────────────────────────
|
||||||
public static ConfigEntry<float> SensesRadius;
|
public static ConfigEntry<float> SensesRadius;
|
||||||
|
|
@ -62,6 +132,12 @@ namespace RacesOfValheim
|
||||||
|
|
||||||
// ─── Devour ────────────────────────────────────────────────────────────
|
// ─── Devour ────────────────────────────────────────────────────────────
|
||||||
public static ConfigEntry<float> DevourCooldown;
|
public static ConfigEntry<float> DevourCooldown;
|
||||||
|
// What a devoured creature feeds - see AswidRace.ApplyFoodBalance.
|
||||||
|
public static ConfigEntry<float> DevourHealthMultiplier;
|
||||||
|
public static ConfigEntry<float> DevourStaminaShare;
|
||||||
|
public static ConfigEntry<float> EarlyStaminaShare;
|
||||||
|
public static ConfigEntry<float> FoodCapBase;
|
||||||
|
public static ConfigEntry<float> FoodCapPerBiome;
|
||||||
|
|
||||||
// ─── Domination (tier 6+ ability, native Interact key) ───────────────────
|
// ─── Domination (tier 6+ ability, native Interact key) ───────────────────
|
||||||
public static ConfigEntry<float> EnslaveCooldown;
|
public static ConfigEntry<float> EnslaveCooldown;
|
||||||
|
|
@ -130,13 +206,95 @@ namespace RacesOfValheim
|
||||||
SurtlingFormDamageBonus = config.Bind(combat, "Surtling Form Damage Bonus", 30f,
|
SurtlingFormDamageBonus = config.Bind(combat, "Surtling Form Damage Bonus", 30f,
|
||||||
new ConfigDescription("Flat damage added to every attack once the tier 8 Surtling form is unlocked.", new AcceptableValueRange<float>(0f, 100f)));
|
new ConfigDescription("Flat damage added to every attack once the tier 8 Surtling form is unlocked.", new AcceptableValueRange<float>(0f, 100f)));
|
||||||
|
|
||||||
|
const string stamina = "Aswid - Stamina";
|
||||||
|
BaseStaminaBonus = config.Bind(stamina, "Base Stamina Bonus", 25f,
|
||||||
|
new ConfigDescription("Max stamina added on top of the game's base 75 and your food, before any boss.", new AcceptableValueRange<float>(0f, 300f)));
|
||||||
|
StaminaBonusPerState = config.Bind(stamina, "Stamina Bonus Per State", 10f,
|
||||||
|
new ConfigDescription("Max stamina added per progression state (8 at Fader).", new AcceptableValueRange<float>(0f, 50f)));
|
||||||
|
StaminaCostMultiplier = config.Bind(stamina, "Stamina Cost Multiplier", 1f,
|
||||||
|
new ConfigDescription("Multiplies every stamina cost: sprinting, swimming, attacks, blocking. 1 is the normal cost, 0.5 half. There is no infinite setting on purpose; set the bonuses above high instead.", new AcceptableValueRange<float>(0.1f, 2f)));
|
||||||
|
|
||||||
|
const string weak = "Aswid - Weaknesses";
|
||||||
|
SunlightEnabled = config.Bind(weak, "Sunlight", true,
|
||||||
|
new ConfigDescription("Weakens you by day while you stand under open sky. A roof (the same test as the game's Sheltered status), a dungeon, the Swamp, the Mistlands, the night and your own Eclipse all shield you.", null));
|
||||||
|
SunHealthRegenPenalty = config.Bind(weak, "Sunlight Health Regen Penalty", 0.5f,
|
||||||
|
new ConfigDescription("Health regeneration lost in sunlight. 0.5 = half.", new AcceptableValueRange<float>(0f, 1f)));
|
||||||
|
SunStaminaRegenPenalty = config.Bind(weak, "Sunlight Stamina Regen Penalty", 0.25f,
|
||||||
|
new ConfigDescription("Stamina regeneration lost in sunlight. 0.25 = a quarter.", new AcceptableValueRange<float>(0f, 1f)));
|
||||||
|
SunSpeedPenalty = config.Bind(weak, "Sunlight Speed Penalty", 0.1f,
|
||||||
|
new ConfigDescription("Movement speed lost in sunlight. 0.1 = 10% slower.", new AcceptableValueRange<float>(0f, 0.9f)));
|
||||||
|
SunHealthLossPerSecond = config.Bind(weak, "Sunlight Health Loss Per Second", 0.5f,
|
||||||
|
new ConfigDescription("Health the sun burns away each second. 0 turns it off.", new AcceptableValueRange<float>(0f, 10f)));
|
||||||
|
SunHealthFloor = config.Bind(weak, "Sunlight Health Floor", 0.3f,
|
||||||
|
new ConfigDescription("The sun stops burning at this fraction of your max health, so it weakens you but never kills you. 0.3 = 30%.", new AcceptableValueRange<float>(0f, 1f)));
|
||||||
|
FireWeaknessEnabled = config.Bind(weak, "Fire Weakness", true,
|
||||||
|
new ConfigDescription("Fire, burning included, hurts more.", null));
|
||||||
|
FireWeakness = config.Bind(weak, "Fire Weakness Amount", 0.25f,
|
||||||
|
new ConfigDescription("Extra fire damage taken. 0.25 = 25% more. Resistance meads and armour still reduce it.", new AcceptableValueRange<float>(0f, 2f)));
|
||||||
|
FaderRemovesFireWeakness = config.Bind(weak, "Fader Removes Fire Weakness", true,
|
||||||
|
new ConfigDescription("Defeating Fader, the boss that grants the Surtling form, ends the fire weakness.", null));
|
||||||
|
PierceWeaknessEnabled = config.Bind(weak, "Pierce Weakness", true,
|
||||||
|
new ConfigDescription("Pierce damage (arrows, spears, stakes) hurts more. Mist Form's immunity still wins.", null));
|
||||||
|
PierceWeakness = config.Bind(weak, "Pierce Weakness Amount", 0.2f,
|
||||||
|
new ConfigDescription("Extra pierce damage taken. 0.2 = 20% more.", new AcceptableValueRange<float>(0f, 2f)));
|
||||||
|
|
||||||
|
const string water = "Aswid - Running Water";
|
||||||
|
RunningWaterEnabled = config.Bind(water, "Running Water", true,
|
||||||
|
new ConfigDescription("Swimming costs more stamina, and open water - the sea, rivers, lakes - hurts you while you swim in it or fly over it. Standing on, steering or sitting in a boat protects you. Wading, docks and bridges are safe.", null));
|
||||||
|
WaterOceanOnly = config.Bind(water, "Ocean Only", false,
|
||||||
|
new ConfigDescription("Limits the burn, the drain and the camera sway to the Ocean biome, leaving rivers and lakes alone. The swim stamina cost applies everywhere either way.", null));
|
||||||
|
SwimStaminaMultiplier = config.Bind(water, "Swim Stamina Multiplier", 2f,
|
||||||
|
new ConfigDescription("Multiplies the stamina swimming costs, anywhere. At 0 stamina the game's own drowning starts. Around 5 and up, swimming any distance is no longer possible.", new AcceptableValueRange<float>(1f, 10f)));
|
||||||
|
SeaHealthLossPerSecond = config.Bind(water, "Open Water Health Loss Per Second", 1f,
|
||||||
|
new ConfigDescription("Health open water burns away each second.", new AcceptableValueRange<float>(0f, 20f)));
|
||||||
|
SeaStaminaDrainPerSecond = config.Bind(water, "Open Water Stamina Drain Per Second", 2f,
|
||||||
|
new ConfigDescription("Stamina open water drains each second, on top of what swimming or flying costs.", new AcceptableValueRange<float>(0f, 30f)));
|
||||||
|
SeaHealthFloor = config.Bind(water, "Open Water Health Floor", 0.1f,
|
||||||
|
new ConfigDescription("The water's burn stops at this fraction of your max health. Drowning, once your stamina runs out, has no floor.", new AcceptableValueRange<float>(0f, 1f)));
|
||||||
|
SeaCameraSway = config.Bind(water, "Camera Sway", true,
|
||||||
|
new ConfigDescription("The camera rolls gently while you are out on the water, on a boat too, as if seasick. Local: each player chooses for themselves.", null));
|
||||||
|
SeaCameraSwayStrength = config.Bind(water, "Camera Sway Strength", 1f,
|
||||||
|
new ConfigDescription("How far the camera rolls. 1 is about 4 degrees. Local.", new AcceptableValueRange<float>(0f, 3f)));
|
||||||
|
|
||||||
const string batform = "Aswid - Bat Form";
|
const string batform = "Aswid - Bat Form";
|
||||||
BatFormAggro = config.Bind(batform, "Monsters Notice The Bat", true,
|
FreeBatFlight = config.Bind(batform, "Free Bat Flight", false,
|
||||||
new ConfigDescription("Lets monsters see, hear and wake up for a player in Bat Form. Vanilla refuses to notice anyone flying on the debug-fly flag, which is the flag the form uses - turn this off to go back to a bat nothing ever looks at."));
|
new ConfigDescription("Off: Stamina Flight, the settings below. On: the old Free Flight, up to 50 m/s with no stamina cost and no weight limit; Jump rises, Left Ctrl sinks. Your own choice, unless the server's Bat Flight Rule forces one. Takes effect the next time you become a bat."));
|
||||||
BatFormVulnerable = config.Bind(batform, "The Bat Can Be Hurt", true,
|
BatFlightRule = config.Bind(batform, "Bat Flight Rule", BatFlightRuleMode.PlayerChoice,
|
||||||
new ConfigDescription("Lets damage land on a player in Bat Form. Same cause as the setting above: vanilla drops every hit on a debug-flying character. Turn this off for a bat that is noticed and chased but cannot be killed."));
|
new ConfigDescription("Server rule. PlayerChoice: each player's Free Bat Flight setting decides. AlwaysStaminaFlight / AlwaysFreeFlight: every bat flies that way. On a server only the host's or the server's value counts."));
|
||||||
BatFormFlightSpeed = config.Bind(batform, "Flight Speed", 1f,
|
// Same controls as the Skadi's drake: aim with the camera, W beats forward, Shift
|
||||||
new ConfigDescription("How fast the bat flies, as a multiplier on the game's own flight speed (20 m/s, and 2.5x that while the run key is held). 1 is untouched, 2 is twice as fast, 0.5 is half. Local only - it changes how your own bat moves, not anyone else's.", new AcceptableValueRange<float>(0.25f, 3f)));
|
// sprints, S beats backwards, and letting go hovers briefly before gliding down.
|
||||||
|
BatTurnSpeed = config.Bind(batform, "Turn Speed", 180f,
|
||||||
|
new ConfigDescription("Degrees per second the bat turns towards where you aim.", new AcceptableValueRange<float>(30f, 720f)));
|
||||||
|
BatGlideSpeed = config.Bind(batform, "Glide Speed", 6f,
|
||||||
|
new ConfigDescription("Speed while gliding down with no key held, in m/s.", new AcceptableValueRange<float>(0f, 30f)));
|
||||||
|
// Not "Flight Speed": that key held the old debug-fly multiplier, and an existing .cfg
|
||||||
|
// would load its 1 here as one metre per second.
|
||||||
|
BatBoostSpeed = config.Bind(batform, "Boost Speed", 13f,
|
||||||
|
new ConfigDescription("Speed while holding W, in m/s. Costs the powered stamina below.", new AcceptableValueRange<float>(0f, 60f)));
|
||||||
|
BatSprintSpeed = config.Bind(batform, "Sprint Speed", 24f,
|
||||||
|
new ConfigDescription("Speed while holding W and Shift, in m/s. Costs the sprint stamina on top. The old bat flew at 50.", new AcceptableValueRange<float>(0f, 80f)));
|
||||||
|
BatReverseSpeed = config.Bind(batform, "Reverse Speed", 8f,
|
||||||
|
new ConfigDescription("Speed while holding S, in m/s. Costs the powered stamina.", new AcceptableValueRange<float>(0f, 40f)));
|
||||||
|
BatLiftoffSpeed = config.Bind(batform, "Liftoff Speed", 9f,
|
||||||
|
new ConfigDescription("Climb speed out of water, in m/s. Always free, so a bat that touches the sea can still leave it.", new AcceptableValueRange<float>(0f, 30f)));
|
||||||
|
BatHoverSeconds = config.Bind(batform, "Hover Seconds", 3f,
|
||||||
|
new ConfigDescription("How long the bat holds its height after the last powered beat before it starts to glide down.", new AcceptableValueRange<float>(0f, 30f)));
|
||||||
|
BatPoweredStaminaPerSecond = config.Bind(batform, "Flight Stamina Per Second", 3f,
|
||||||
|
new ConfigDescription("Stamina per second while holding W or S. Out of stamina, the bat can only glide. 0 makes flight free, like the drake's.", new AcceptableValueRange<float>(0f, 60f)));
|
||||||
|
BatSprintStaminaPerSecond = config.Bind(batform, "Sprint Stamina Per Second", 12f,
|
||||||
|
new ConfigDescription("Extra stamina per second while sprinting, on top of the flight cost.", new AcceptableValueRange<float>(0f, 60f)));
|
||||||
|
BatEncumbered = config.Bind(batform, "While Encumbered", EncumberedMode.Allowed,
|
||||||
|
new ConfigDescription("Allowed: the bat flies while you carry too much, at the extra stamina cost below. Blocked: you cannot take bat form while encumbered, and a bat that becomes encumbered in the air can only glide down.", null));
|
||||||
|
BatEncumberedExtraCost = config.Bind(batform, "Encumbered Extra Stamina Cost", 0.15f,
|
||||||
|
new ConfigDescription("With 'Allowed' above: how much more flight and sprint cost while encumbered. 0.15 = 15% more.", new AcceptableValueRange<float>(0f, 1f)));
|
||||||
|
BatMaxDuration = config.Bind(batform, "Max Duration", 0f,
|
||||||
|
new ConfigDescription("Seconds the bat form lasts before you turn back on your own. 0 means no limit: stamina is the limit.", new AcceptableValueRange<float>(0f, 3600f)));
|
||||||
|
BatDurationPerState = config.Bind(batform, "Duration Per State", 0f,
|
||||||
|
new ConfigDescription("Seconds added to the max duration per progression state. Does nothing while the max duration is 0.", new AcceptableValueRange<float>(0f, 600f)));
|
||||||
|
BatCooldown = config.Bind(batform, "Cooldown", 0f,
|
||||||
|
new ConfigDescription("Seconds after leaving bat form before you can take it again. 0 means none.", new AcceptableValueRange<float>(0f, 3600f)));
|
||||||
|
BatCombatLock = config.Bind(batform, "Combat Lock", 2.5f,
|
||||||
|
new ConfigDescription("Seconds after you last lost health (a hit, or a tick of fire, poison or bleeding) before you can take bat form. Turning back from bat form is never blocked. 0 means none.", new AcceptableValueRange<float>(0f, 30f)));
|
||||||
|
|
||||||
const string aura = "Aswid - Vampiric Aura";
|
const string aura = "Aswid - Vampiric Aura";
|
||||||
AuraTickInterval = config.Bind(aura, "Tick Interval", 0.25f,
|
AuraTickInterval = config.Bind(aura, "Tick Interval", 0.25f,
|
||||||
|
|
@ -151,6 +309,10 @@ namespace RacesOfValheim
|
||||||
new ConfigDescription("Extra damage per tick at 100 Blood Magic skill (scales linearly from 0).", new AcceptableValueRange<float>(0f, 20f)));
|
new ConfigDescription("Extra damage per tick at 100 Blood Magic skill (scales linearly from 0).", new AcceptableValueRange<float>(0f, 20f)));
|
||||||
AuraExecuteThreshold = config.Bind(aura, "Execute Threshold", 0.20f,
|
AuraExecuteThreshold = config.Bind(aura, "Execute Threshold", 0.20f,
|
||||||
new ConfigDescription("Non-boss enemies at or below this fraction of max health are executed by the aura instead of merely damaged.", new AcceptableValueRange<float>(0f, 1f)));
|
new ConfigDescription("Non-boss enemies at or below this fraction of max health are executed by the aura instead of merely damaged.", new AcceptableValueRange<float>(0f, 1f)));
|
||||||
|
AuraInBatForm = config.Bind(aura, "Active In Bat Form", false,
|
||||||
|
new ConfigDescription("Lets the aura drain while you are a bat from the start, as it did before. Off: the bat has no aura until the unlock state below.", null));
|
||||||
|
BatAuraUnlockState = config.Bind(aura, "Bat Form Unlock State", 7,
|
||||||
|
new ConfigDescription("The progression state at which the bat gets its aura back (7 = The Queen). 0 means never, so only the setting above can turn it on.", new AcceptableValueRange<int>(0, 8)));
|
||||||
|
|
||||||
const string senses = "Aswid - Superhuman Senses";
|
const string senses = "Aswid - Superhuman Senses";
|
||||||
SensesRadius = config.Bind(senses, "Detection Radius", 100f,
|
SensesRadius = config.Bind(senses, "Detection Radius", 100f,
|
||||||
|
|
@ -173,6 +335,23 @@ namespace RacesOfValheim
|
||||||
const string devour = "Aswid - Devour";
|
const string devour = "Aswid - Devour";
|
||||||
DevourCooldown = config.Bind(devour, "Consume Cooldown", 5f,
|
DevourCooldown = config.Bind(devour, "Consume Cooldown", 5f,
|
||||||
new ConfigDescription("How long one body stays drunk-dry, in seconds. A single death is reported to the devour more than once - by two damage patches, by the aura's execute, by a thrall's kill - and this is the window that keeps those from feeding you twice off the same corpse. It is per body, not per player: killing a whole pack at once devours every one of them. One second is used as the floor, so no corpse feeds you twice even at 0.", new AcceptableValueRange<float>(0f, 60f)));
|
new ConfigDescription("How long one body stays drunk-dry, in seconds. A single death is reported to the devour more than once - by two damage patches, by the aura's execute, by a thrall's kill - and this is the window that keeps those from feeding you twice off the same corpse. It is per body, not per player: killing a whole pack at once devours every one of them. One second is used as the floor, so no corpse feeds you twice even at 0.", new AcceptableValueRange<float>(0f, 60f)));
|
||||||
|
DevourHealthMultiplier = config.Bind(devour, "Health Multiplier", 0.9f,
|
||||||
|
new ConfigDescription("Scales the health every devoured creature feeds you. 1 is the old amount.", new AcceptableValueRange<float>(0f, 2f)));
|
||||||
|
DevourStaminaShare = config.Bind(devour, "Stamina Share", 0.10f,
|
||||||
|
new ConfigDescription("Fraction of that health turned into stamina instead, for creatures past the Black Forest. 0.1 = 10%.", new AcceptableValueRange<float>(0f, 1f)));
|
||||||
|
EarlyStaminaShare = config.Bind(devour, "Early Creature Stamina Share", 0.60f,
|
||||||
|
new ConfigDescription("The same, for Meadows and Black Forest creatures. Above 0.5 they feed more stamina than health. Set it equal to the one above to treat every creature alike.", new AcceptableValueRange<float>(0f, 1f)));
|
||||||
|
FoodCapBase = config.Bind(devour, "Food Health Cap Base", 15f,
|
||||||
|
new ConfigDescription("Creatures with no hand-set meal feed half their health. That is capped at this plus the per-biome value times the biome's number (Meadows 1 ... Deep North 8). With the defaults: Black Forest 45, Mountains 75, Plains 90.", new AcceptableValueRange<float>(0f, 150f)));
|
||||||
|
FoodCapPerBiome = config.Bind(devour, "Food Health Cap Per Biome", 15f,
|
||||||
|
new ConfigDescription("See the base cap above.", new AcceptableValueRange<float>(0f, 50f)));
|
||||||
|
|
||||||
|
// Jotunn's server sync assigns Value, which fires SettingChanged, so the server's
|
||||||
|
// numbers reach the foods the same way a local drag does.
|
||||||
|
foreach (var entry in new[] { DevourHealthMultiplier, DevourStaminaShare, EarlyStaminaShare, FoodCapBase, FoodCapPerBiome })
|
||||||
|
{
|
||||||
|
entry.SettingChanged += (_, __) => AswidRace.ApplyAllFoodBalance();
|
||||||
|
}
|
||||||
|
|
||||||
const string domination = "Aswid - Domination";
|
const string domination = "Aswid - Domination";
|
||||||
EnslaveCooldown = config.Bind(domination, "Enslave Cooldown", 900f,
|
EnslaveCooldown = config.Bind(domination, "Enslave Cooldown", 900f,
|
||||||
|
|
@ -297,7 +476,7 @@ namespace RacesOfValheim
|
||||||
new ConfigDescription("As above, around the third axis. The default half turn is what rights the borrowed socket, which arrives upside down on a player's head bone.",
|
new ConfigDescription("As above, around the third axis. The default half turn is what rights the borrowed socket, which arrives upside down on a player's head bone.",
|
||||||
new AcceptableValueRange<float>(-180f, 180f), new ConfigurationManagerAttributes { Order = 58 }));
|
new AcceptableValueRange<float>(-180f, 180f), new ConfigurationManagerAttributes { Order = 58 }));
|
||||||
|
|
||||||
EyeSmoke = config.Bind(eyes, "Eye Smoke", true,
|
EyeSmoke = config.Bind(eyes, "Eye Smoke", false,
|
||||||
new ConfigDescription("Lights the smoke the creature carries inside its own sockets and leaves switched off. Tinted to match the eyes, so it turns with them at the last stage.",
|
new ConfigDescription("Lights the smoke the creature carries inside its own sockets and leaves switched off. Tinted to match the eyes, so it turns with them at the last stage.",
|
||||||
null, new ConfigurationManagerAttributes { Order = 50 }));
|
null, new ConfigurationManagerAttributes { Order = 50 }));
|
||||||
EyeFlatColorShader = config.Bind(eyes, "Eye Flat Colour Shader", false,
|
EyeFlatColorShader = config.Bind(eyes, "Eye Flat Colour Shader", false,
|
||||||
|
|
|
||||||
|
|
@ -219,6 +219,32 @@ namespace RacesOfValheim
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Fire and pierce hurt the Aswid more: fire for the old way vampires end, pierce for the
|
||||||
|
/// stake. A plain multiplier, like the Trol's fire weakness, rather than DamageModifier.Weak,
|
||||||
|
/// which is a fixed +50% with nothing in between. ApplyDamage runs after resistances, so a
|
||||||
|
/// fire resistance mead still helps, and Mist Form's pierce immunity has already zeroed the
|
||||||
|
/// pierce by the time this sees it.
|
||||||
|
/// </summary>
|
||||||
|
[HarmonyPatch(typeof(Character), "ApplyDamage")]
|
||||||
|
public static class Aswid_Weakness_Patch
|
||||||
|
{
|
||||||
|
public static void Prefix(Character __instance, ref HitData hit)
|
||||||
|
{
|
||||||
|
if (__instance != Player.m_localPlayer || !AswidRace.IsAswid()) return;
|
||||||
|
|
||||||
|
if (AswidRace.HasFireWeakness(BossProgressionManager.GetCurrentProgressionState()) && hit.m_damage.m_fire > 0f)
|
||||||
|
{
|
||||||
|
hit.m_damage.m_fire *= 1f + AswidConfig.FireWeakness.Value;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (AswidConfig.PierceWeaknessEnabled.Value && hit.m_damage.m_pierce > 0f)
|
||||||
|
{
|
||||||
|
hit.m_damage.m_pierce *= 1f + AswidConfig.PierceWeakness.Value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
[HarmonyPatch(typeof(Humanoid), "StartAttack")]
|
[HarmonyPatch(typeof(Humanoid), "StartAttack")]
|
||||||
public static class Aswid_Attack_Patch
|
public static class Aswid_Attack_Patch
|
||||||
{
|
{
|
||||||
|
|
@ -497,7 +523,7 @@ namespace RacesOfValheim
|
||||||
{
|
{
|
||||||
public static bool Prefix(Hud __instance, Player player)
|
public static bool Prefix(Hud __instance, Player player)
|
||||||
{
|
{
|
||||||
if (player == Player.m_localPlayer && (AswidRace.IsAswid() || DraughRace.IsDraugh()))
|
if (player == Player.m_localPlayer && DraughRace.IsDraugh())
|
||||||
{
|
{
|
||||||
if (__instance.m_staminaBar2Root != null && __instance.m_staminaBar2Root.gameObject.activeSelf)
|
if (__instance.m_staminaBar2Root != null && __instance.m_staminaBar2Root.gameObject.activeSelf)
|
||||||
{
|
{
|
||||||
|
|
@ -507,7 +533,8 @@ namespace RacesOfValheim
|
||||||
}
|
}
|
||||||
|
|
||||||
// Vanilla switches the bar on once, when the HUD is built, and never again. Without
|
// Vanilla switches the bar on once, when the HUD is built, and never again. Without
|
||||||
// this a player who left the Aswid or the Draugh had no stamina bar until relog.
|
// this a player who left the Draugh had no stamina bar until relog - and an Aswid
|
||||||
|
// updating from a version that still hid it would have none either.
|
||||||
if (player == Player.m_localPlayer && __instance.m_staminaBar2Root != null
|
if (player == Player.m_localPlayer && __instance.m_staminaBar2Root != null
|
||||||
&& !__instance.m_staminaBar2Root.gameObject.activeSelf)
|
&& !__instance.m_staminaBar2Root.gameObject.activeSelf)
|
||||||
{
|
{
|
||||||
|
|
@ -597,6 +624,13 @@ namespace RacesOfValheim
|
||||||
{
|
{
|
||||||
bool isBat = nview.GetZDO().GetBool("Aswid_IsBatForm", false);
|
bool isBat = nview.GetZDO().GetBool("Aswid_IsBatForm", false);
|
||||||
bool isMist = nview.GetZDO().GetBool("Aswid_IsMistForm", false);
|
bool isMist = nview.GetZDO().GetBool("Aswid_IsMistForm", false);
|
||||||
|
|
||||||
|
// The bat flies on m_flying, which only the bat's own client sets. Mirror it here
|
||||||
|
// and switch gravity off for the duration, or this copy sinks to the terrain
|
||||||
|
// whatever altitude is replicated - the same fix ZdoVisualSync applies to drakes.
|
||||||
|
HarmonyLib.Traverse.Create(player).Field("m_flying").SetValue(isBat);
|
||||||
|
Rigidbody body = player.GetComponent<Rigidbody>();
|
||||||
|
if (body != null && body.useGravity == isBat) body.useGravity = !isBat;
|
||||||
|
|
||||||
Transform playerVisual = player.transform.Find("Visual");
|
Transform playerVisual = player.transform.Find("Visual");
|
||||||
|
|
||||||
|
|
@ -820,6 +854,104 @@ namespace RacesOfValheim
|
||||||
stamina += extraFood.m_stamina;
|
stamina += extraFood.m_stamina;
|
||||||
eitr += extraFood.m_eitr;
|
eitr += extraFood.m_eitr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Added on top of whatever vanilla and other mods put here, never assigned: a mod that
|
||||||
|
// raises max stamina has to keep raising it for an Aswid too.
|
||||||
|
stamina += AswidRace.GetStaminaBonus(BossProgressionManager.GetCurrentProgressionState());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The Aswid's stamina. It used to be infinite: the Skeleton's UseStamina skip covered the
|
||||||
|
/// Aswid too, which made every stamina mod, food and skill meaningless for the race (the Discord
|
||||||
|
/// reports that started the rebalance). The cost is now scaled rather than skipped, so the
|
||||||
|
/// call still reaches vanilla - and any other mod patching it - with a smaller number.
|
||||||
|
/// </summary>
|
||||||
|
[HarmonyPatch(typeof(Player), "UseStamina")]
|
||||||
|
public static class Aswid_UseStamina_Patch
|
||||||
|
{
|
||||||
|
public static void Prefix(Player __instance, ref float v)
|
||||||
|
{
|
||||||
|
if (__instance != Player.m_localPlayer || !AswidRace.IsAswid()) return;
|
||||||
|
v *= AswidConfig.StaminaCostMultiplier.Value;
|
||||||
|
|
||||||
|
if (Aswid_SwimCost_Patch.Swimming && AswidConfig.RunningWaterEnabled.Value)
|
||||||
|
{
|
||||||
|
v *= AswidConfig.SwimStaminaMultiplier.Value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Marks the frames where vanilla charges for a swim stroke, so Aswid_UseStamina_Patch can
|
||||||
|
/// make that one cost dearer. Player.OnSwimming is the only place swimming spends stamina,
|
||||||
|
/// and it also runs the drowning check right after - which is what makes a high multiplier
|
||||||
|
/// play as "cannot swim" without any code of ours deciding who drowns.
|
||||||
|
/// </summary>
|
||||||
|
[HarmonyPatch(typeof(Player), "OnSwimming")]
|
||||||
|
public static class Aswid_SwimCost_Patch
|
||||||
|
{
|
||||||
|
public static bool Swimming { get; private set; }
|
||||||
|
|
||||||
|
public static void Prefix(Player __instance)
|
||||||
|
{
|
||||||
|
Swimming = __instance == Player.m_localPlayer;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void Finalizer()
|
||||||
|
{
|
||||||
|
Swimming = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The seasick camera: a slow roll while the Aswid is out on the water, on a boat too. Applied after
|
||||||
|
/// vanilla has settled the camera's rotation for the frame, as a roll around the view axis,
|
||||||
|
/// so it never moves where the player aims - only how the horizon sits.
|
||||||
|
/// </summary>
|
||||||
|
[HarmonyPatch(typeof(GameCamera), "GetCameraPosition")]
|
||||||
|
public static class Aswid_SeaCameraSway_Patch
|
||||||
|
{
|
||||||
|
private const float DegreesAtStrengthOne = 4f;
|
||||||
|
private static float sway;
|
||||||
|
|
||||||
|
public static void Postfix(float dt, ref Quaternion rot)
|
||||||
|
{
|
||||||
|
bool on = AswidRace.OnWater && AswidConfig.SeaCameraSway.Value && AswidRace.IsAswid() &&
|
||||||
|
Player.m_localPlayer != null && !Player.m_localPlayer.IsDead();
|
||||||
|
|
||||||
|
// Eased in and out over about a second, so leaving the sea does not snap the horizon.
|
||||||
|
sway = Mathf.MoveTowards(sway, on ? 1f : 0f, dt);
|
||||||
|
if (sway <= 0f) return;
|
||||||
|
|
||||||
|
float t = Time.time;
|
||||||
|
float roll = (Mathf.Sin(t * 0.9f) + 0.4f * Mathf.Sin(t * 2.3f)) * DegreesAtStrengthOne *
|
||||||
|
AswidConfig.SeaCameraSwayStrength.Value * sway;
|
||||||
|
rot *= Quaternion.AngleAxis(roll, Vector3.forward);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Pukeberries empty the fourth stomach too.
|
||||||
|
///
|
||||||
|
/// SE_Puke calls RemoveOneFood once a second, and vanilla only ever picks from its own three
|
||||||
|
/// slots, so the Aswid's fourth meal survived the berries. It now goes into the same random
|
||||||
|
/// draw as the other three, the way the Trol's extra slots do.
|
||||||
|
/// </summary>
|
||||||
|
[HarmonyPatch(typeof(Player), "RemoveOneFood")]
|
||||||
|
public static class Aswid_PlayerRemoveOneFood_Patch
|
||||||
|
{
|
||||||
|
public static bool Prefix(Player __instance, System.Collections.Generic.List<Player.Food> ___m_foods, ref bool __result)
|
||||||
|
{
|
||||||
|
if (__instance != Player.m_localPlayer || !AswidRace.IsAswid()) return true;
|
||||||
|
if (!AswidFoodManager.ExtraFoods.TryGetValue(__instance, out Player.Food extraFood) || extraFood == null) return true;
|
||||||
|
|
||||||
|
int vanillaCount = ___m_foods != null ? ___m_foods.Count : 0;
|
||||||
|
if (Random.Range(0, vanillaCount + 1) < vanillaCount) return true; // one of vanilla's three
|
||||||
|
|
||||||
|
AswidFoodManager.ClearFood(__instance);
|
||||||
|
__result = true;
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -191,6 +191,11 @@ namespace RacesOfValheim
|
||||||
if (c != null)
|
if (c != null)
|
||||||
{
|
{
|
||||||
float foodHp = Mathf.Min(c.m_health / 2f, 150f);
|
float foodHp = Mathf.Min(c.m_health / 2f, 150f);
|
||||||
|
// The formula alone only knows how big a creature is, not where it
|
||||||
|
// lives - a Black Forest troll came out at 150. Only these get the
|
||||||
|
// per-biome cap in ApplyFoodBalance; the hand-set values below are
|
||||||
|
// choices, not formula output, and keep theirs.
|
||||||
|
bool fromFormula = true;
|
||||||
// Capped at 50 minutes: a tough creature like the Barka would otherwise
|
// Capped at 50 minutes: a tough creature like the Barka would otherwise
|
||||||
// feed for over an hour.
|
// feed for over an hour.
|
||||||
float burnTime = Mathf.Min(c.m_health * 2f, 3000f);
|
float burnTime = Mathf.Min(c.m_health * 2f, 3000f);
|
||||||
|
|
@ -201,24 +206,38 @@ namespace RacesOfValheim
|
||||||
{
|
{
|
||||||
burnTime = 1200f; // 20 minutes
|
burnTime = 1200f; // 20 minutes
|
||||||
}
|
}
|
||||||
else if (mobName == "JotunWitch") { foodHp = 120f; burnTime = 3600f; } // 60 minutes
|
else if (mobName == "JotunWitch") { foodHp = 120f; burnTime = 3600f; fromFormula = false; } // 60 minutes
|
||||||
else if (mobName == "ElakingMole") { foodHp = 100f; burnTime = 1800f; } // 30 minutes
|
else if (mobName == "ElakingMole") { foodHp = 100f; burnTime = 1800f; fromFormula = false; } // 30 minutes
|
||||||
else if (mobName.StartsWith("Dverger") && mobName != "DvergerDeepNorth") { foodHp = 90f; burnTime = 1500f; } // 25 minutes
|
else if (mobName.StartsWith("Dverger") && mobName != "DvergerDeepNorth") { foodHp = 90f; burnTime = 1500f; fromFormula = false; } // 25 minutes
|
||||||
else if (mobName == "DvergerDeepNorth") { foodHp = 100f; burnTime = 1800f; } // 30 minutes
|
else if (mobName == "DvergerDeepNorth") { foodHp = 100f; burnTime = 1800f; fromFormula = false; } // 30 minutes
|
||||||
else if (mobName == "Greyling") { foodHp = 20f; burnTime = 1200f; }
|
else if (mobName == "Greyling") { foodHp = 20f; burnTime = 1200f; fromFormula = false; }
|
||||||
else if (mobName == "Greydwarf") { foodHp = 25f; burnTime = 1200f; }
|
else if (mobName == "Greydwarf") { foodHp = 25f; burnTime = 1200f; fromFormula = false; }
|
||||||
else if (mobName == "Greydwarf_Shaman") { foodHp = 30f; burnTime = 1200f; }
|
else if (mobName == "Greydwarf_Shaman") { foodHp = 30f; burnTime = 1200f; fromFormula = false; }
|
||||||
else if (mobName == "Greydwarf_Elite") { foodHp = 60f; burnTime = 1800f; }
|
else if (mobName == "Greydwarf_Elite") { foodHp = 60f; burnTime = 1800f; fromFormula = false; }
|
||||||
|
|
||||||
customItem.ItemDrop.m_itemData.m_shared.m_food = foodHp;
|
customItem.ItemDrop.m_itemData.m_shared.m_food = foodHp;
|
||||||
customItem.ItemDrop.m_itemData.m_shared.m_foodStamina = 0f;
|
customItem.ItemDrop.m_itemData.m_shared.m_foodStamina = 0f;
|
||||||
customItem.ItemDrop.m_itemData.m_shared.m_foodEitr = 0f;
|
customItem.ItemDrop.m_itemData.m_shared.m_foodEitr = 0f;
|
||||||
customItem.ItemDrop.m_itemData.m_shared.m_foodBurnTime = burnTime;
|
customItem.ItemDrop.m_itemData.m_shared.m_foodBurnTime = burnTime;
|
||||||
customItem.ItemDrop.m_itemData.m_shared.m_foodRegen = Mathf.Max(1f, foodHp / 15f);
|
customItem.ItemDrop.m_itemData.m_shared.m_foodRegen = Mathf.Max(1f, foodHp / 15f);
|
||||||
|
if (fromFormula) formulaFoods.Add(foodName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// What the item gives before any balance setting, kept so ApplyFoodBalance can be
|
||||||
|
// rerun from scratch whenever a setting changes or the server's values arrive.
|
||||||
|
var shared = customItem.ItemDrop.m_itemData.m_shared;
|
||||||
|
baseFoods[foodName] = new BaseFood
|
||||||
|
{
|
||||||
|
Mob = mobName,
|
||||||
|
Health = shared.m_food,
|
||||||
|
Stamina = shared.m_foodStamina,
|
||||||
|
Regen = shared.m_foodRegen,
|
||||||
|
Shared = shared
|
||||||
|
};
|
||||||
|
ApplyFoodBalance(foodName);
|
||||||
|
|
||||||
GameObject trophyPrefab = Jotunn.Managers.PrefabManager.Cache.GetPrefab<GameObject>(trophyName);
|
GameObject trophyPrefab = Jotunn.Managers.PrefabManager.Cache.GetPrefab<GameObject>(trophyName);
|
||||||
if (trophyPrefab != null)
|
if (trophyPrefab != null)
|
||||||
{
|
{
|
||||||
|
|
@ -234,10 +253,82 @@ namespace RacesOfValheim
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private float m_tintCheckTimer = 0f;
|
private class BaseFood
|
||||||
private float sensesCheckTimer = 0f;
|
{
|
||||||
|
public string Mob;
|
||||||
|
public float Health;
|
||||||
|
public float Stamina;
|
||||||
|
public float Regen;
|
||||||
|
public ItemDrop.ItemData.SharedData Shared;
|
||||||
|
}
|
||||||
|
|
||||||
private Dictionary<Character, GameObject> activeSensesLight = new Dictionary<Character, GameObject>();
|
private static readonly Dictionary<string, BaseFood> baseFoods = new Dictionary<string, BaseFood>();
|
||||||
|
private static readonly HashSet<string> formulaFoods = new HashSet<string>();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The biome each edible creature lives in, as a number from 1 (Meadows) to 8 (Deep North).
|
||||||
|
/// It decides two things: the cap on formula-made foods, and which creatures count as early
|
||||||
|
/// game (1 and 2) for the larger stamina share. A creature missing here counts as tier 8,
|
||||||
|
/// which means uncapped in practice and never early.
|
||||||
|
/// </summary>
|
||||||
|
private static readonly Dictionary<string, int> mobBiomeTier = new Dictionary<string, int>
|
||||||
|
{
|
||||||
|
{ "Boar", 1 }, { "Neck", 1 }, { "Deer", 1 }, { "Greyling", 1 },
|
||||||
|
{ "Greydwarf", 2 }, { "Greydwarf_Elite", 2 }, { "Greydwarf_Shaman", 2 }, { "Troll", 2 },
|
||||||
|
{ "Leech", 3 },
|
||||||
|
{ "Wolf", 4 }, { "Fenring", 4 }, { "Fenring_Cultist", 4 }, { "Ulv", 4 }, { "Hatchling", 4 },
|
||||||
|
{ "Lox", 5 }, { "Goblin", 5 }, { "GoblinArcher", 5 }, { "GoblinShaman", 5 }, { "GoblinBrute", 5 }, { "Deathsquito", 5 },
|
||||||
|
{ "Hare", 6 }, { "Seeker", 6 }, { "SeekerBrood", 6 }, { "SeekerBrute", 6 }, { "Gjall", 6 }, { "Tick", 6 },
|
||||||
|
{ "Dverger", 6 }, { "DvergerMage", 6 }, { "DvergerMageFire", 6 }, { "DvergerMageIce", 6 }, { "DvergerMageSupport", 6 },
|
||||||
|
{ "Asksvin", 7 }, { "Volture", 7 }, { "DvergerAshlands", 7 },
|
||||||
|
};
|
||||||
|
|
||||||
|
public const int EarlyBiomeTier = 2;
|
||||||
|
|
||||||
|
private static int GetBiomeTier(string mob) => mobBiomeTier.TryGetValue(mob, out int tier) ? tier : 8;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Rewrites one devour food from its unbalanced base and the current settings. The Discord
|
||||||
|
/// reports said even weak kills fed too much health; Dissolution asked for about 10% less,
|
||||||
|
/// and for early creatures to feed stamina more than health. So: health is scaled first,
|
||||||
|
/// then a share of it moves over to stamina. Vanilla meals the food was cloned from keep
|
||||||
|
/// the stamina they already had, the share goes on top.
|
||||||
|
///
|
||||||
|
/// Writing the shared data is enough to reach every copy: eaten foods, the extra slot and
|
||||||
|
/// the tooltip all read the same SharedData through their ItemData.
|
||||||
|
/// </summary>
|
||||||
|
private static void ApplyFoodBalance(string foodName)
|
||||||
|
{
|
||||||
|
if (!baseFoods.TryGetValue(foodName, out BaseFood food) || food.Shared == null) return;
|
||||||
|
|
||||||
|
int tier = GetBiomeTier(food.Mob);
|
||||||
|
float health = food.Health;
|
||||||
|
if (formulaFoods.Contains(foodName))
|
||||||
|
{
|
||||||
|
health = Mathf.Min(health, AswidConfig.FoodCapBase.Value + AswidConfig.FoodCapPerBiome.Value * tier);
|
||||||
|
}
|
||||||
|
|
||||||
|
float healthMultiplier = AswidConfig.DevourHealthMultiplier.Value;
|
||||||
|
health *= healthMultiplier;
|
||||||
|
|
||||||
|
float share = tier <= EarlyBiomeTier ? AswidConfig.EarlyStaminaShare.Value : AswidConfig.DevourStaminaShare.Value;
|
||||||
|
float moved = health * share;
|
||||||
|
|
||||||
|
food.Shared.m_food = health - moved;
|
||||||
|
food.Shared.m_foodStamina = food.Stamina + moved;
|
||||||
|
// Regen follows the health the food ends up giving, cap included, so a troll capped
|
||||||
|
// to 40 health does not keep the 10 per tick its old 150 earned.
|
||||||
|
float healthRatio = food.Health > 0f ? food.Shared.m_food / food.Health : 0f;
|
||||||
|
food.Shared.m_foodRegen = Mathf.Max(1f, food.Regen * healthRatio);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>Hooked to the balance settings, which also fire when the server's values arrive.</summary>
|
||||||
|
public static void ApplyAllFoodBalance()
|
||||||
|
{
|
||||||
|
foreach (string foodName in baseFoods.Keys) ApplyFoodBalance(foodName);
|
||||||
|
}
|
||||||
|
|
||||||
|
private float m_tintCheckTimer = 0f;
|
||||||
|
|
||||||
public static float GetEnslaveCooldown()
|
public static float GetEnslaveCooldown()
|
||||||
{
|
{
|
||||||
|
|
@ -279,6 +370,7 @@ namespace RacesOfValheim
|
||||||
{
|
{
|
||||||
seman.RemoveStatusEffect(myHash);
|
seman.RemoveStatusEffect(myHash);
|
||||||
}
|
}
|
||||||
|
HunterSenses.Clear();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -287,64 +379,8 @@ namespace RacesOfValheim
|
||||||
seman.AddStatusEffect(myHash, true);
|
seman.AddStatusEffect(myHash, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
sensesCheckTimer -= Time.deltaTime;
|
int markHash = "SE_AswidSensesMark".GetStableHashCode();
|
||||||
if (sensesCheckTimer <= 0f)
|
HunterSenses.Tick(AswidConfig.SensesRadius.Value, c => c.GetSEMan().AddStatusEffect(markHash, true));
|
||||||
{
|
|
||||||
sensesCheckTimer = AswidConfig.SensesRefreshInterval.Value; // TTL is 2s
|
|
||||||
|
|
||||||
List<Character> allChars = Character.GetAllCharacters();
|
|
||||||
Vector3 myPos = Player.m_localPlayer.transform.position;
|
|
||||||
|
|
||||||
int markHash = "SE_AswidSensesMark".GetStableHashCode();
|
|
||||||
HashSet<Character> inRangeChars = new HashSet<Character>();
|
|
||||||
|
|
||||||
foreach (var c in allChars)
|
|
||||||
{
|
|
||||||
if (c == null || c == Player.m_localPlayer || c.IsDead() || c.IsTamed()) continue;
|
|
||||||
|
|
||||||
float dist = Vector3.Distance(c.transform.position, myPos);
|
|
||||||
if (dist <= AswidConfig.SensesRadius.Value)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
inRangeChars.Add(c);
|
|
||||||
c.GetSEMan().AddStatusEffect(markHash, true); // Keep the malus as requested
|
|
||||||
|
|
||||||
// Locally generate the visual
|
|
||||||
if (!activeSensesLight.ContainsKey(c))
|
|
||||||
{
|
|
||||||
GameObject lightObj = new GameObject("AswidSensesLight");
|
|
||||||
lightObj.transform.SetParent(c.transform);
|
|
||||||
lightObj.transform.position = c.GetCenterPoint();
|
|
||||||
|
|
||||||
Light pLight = lightObj.AddComponent<Light>();
|
|
||||||
pLight.type = LightType.Point;
|
|
||||||
pLight.color = Color.green;
|
|
||||||
pLight.range = AswidConfig.SensesLightRange.Value;
|
|
||||||
pLight.intensity = AswidConfig.SensesLightIntensity.Value;
|
|
||||||
pLight.shadows = LightShadows.None;
|
|
||||||
|
|
||||||
activeSensesLight[c] = lightObj;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
Jotunn.Logger.LogError($"[Aswid] Error processing mob {c.name}: {ex}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
List<Character> keysToRemove = new List<Character>();
|
|
||||||
foreach (var kvp in activeSensesLight)
|
|
||||||
{
|
|
||||||
if (kvp.Key == null || kvp.Key.IsDead() || !inRangeChars.Contains(kvp.Key))
|
|
||||||
{
|
|
||||||
if (kvp.Value != null) Destroy(kvp.Value);
|
|
||||||
keysToRemove.Add(kvp.Key);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
foreach (var k in keysToRemove) activeSensesLight.Remove(k);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
|
@ -352,15 +388,6 @@ namespace RacesOfValheim
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ClearSuperhumanSenses()
|
|
||||||
{
|
|
||||||
foreach (var kvp in activeSensesLight)
|
|
||||||
{
|
|
||||||
if (kvp.Value != null) Destroy(kvp.Value);
|
|
||||||
}
|
|
||||||
activeSensesLight.Clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
private bool? wasNight = null;
|
private bool? wasNight = null;
|
||||||
|
|
||||||
private void Update()
|
private void Update()
|
||||||
|
|
@ -414,6 +441,8 @@ namespace RacesOfValheim
|
||||||
{
|
{
|
||||||
updateTimer = 0f;
|
updateTimer = 0f;
|
||||||
UpdateAswidState();
|
UpdateAswidState();
|
||||||
|
UpdateSunlight(UpdateInterval);
|
||||||
|
UpdateOpenSea(UpdateInterval);
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
|
|
@ -580,9 +609,38 @@ namespace RacesOfValheim
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (AswidConfig.BatEncumbered.Value == AswidConfig.EncumberedMode.Blocked && Player.m_localPlayer.IsEncumbered())
|
||||||
|
{
|
||||||
|
Player.m_localPlayer.Message(MessageHud.MessageType.Center, ModText.Get("rov_msg_aswid_too_heavy_for_bat"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// No escaping a fight by taking wing mid-blow: the form waits until the hits stop.
|
||||||
|
float hurtLeft = AswidConfig.BatCombatLock.Value - (Time.time - LastHurtTime);
|
||||||
|
if (hurtLeft > 0f)
|
||||||
|
{
|
||||||
|
Player.m_localPlayer.Message(MessageHud.MessageType.Center, ModText.Get("rov_msg_aswid_bat_combat_lock", Mathf.CeilToInt(hurtLeft)));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
float cooldownLeft = AswidConfig.BatCooldown.Value - (Time.time - lastBatEndTime);
|
||||||
|
if (cooldownLeft > 0f)
|
||||||
|
{
|
||||||
|
Player.m_localPlayer.Message(MessageHud.MessageType.Center, ModText.Get("rov_msg_aswid_bat_cooldown", Mathf.CeilToInt(cooldownLeft)));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
RunFormRoutine(TransformIntoBatRoutine(rules));
|
RunFormRoutine(TransformIntoBatRoutine(rules));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// When the bat form last ended, for the optional cooldown. Starts far enough back that a
|
||||||
|
// fresh session never begins on cooldown.
|
||||||
|
private float lastBatEndTime = -100000f;
|
||||||
|
|
||||||
|
// When the local player last lost health, for the bat's combat lock. Written by
|
||||||
|
// Aswid_BatCombatLock_Patch for every race; only the Aswid reads it.
|
||||||
|
public static float LastHurtTime = -100000f;
|
||||||
|
|
||||||
// The one bat or mist routine in flight, if any. Kept so ResetRace can stop it: a
|
// The one bat or mist routine in flight, if any. Kept so ResetRace can stop it: a
|
||||||
// TransformIntoBatRoutine left running through a reset finishes its 1.1s gesture and
|
// TransformIntoBatRoutine left running through a reset finishes its 1.1s gesture and
|
||||||
// turns a freshly reset Human into a bat.
|
// turns a freshly reset Human into a bat.
|
||||||
|
|
@ -656,7 +714,7 @@ namespace RacesOfValheim
|
||||||
/// Update() has already bailed out on IsDead(), so a coroutine started here would be the
|
/// Update() has already bailed out on IsDead(), so a coroutine started here would be the
|
||||||
/// only thing still running on a corpse.
|
/// only thing still running on a corpse.
|
||||||
///
|
///
|
||||||
/// Leaving the form up costs more than a missing animation: m_debugFly stays on, so the
|
/// Leaving the form up costs more than a missing animation: m_flying stays on, so the
|
||||||
/// respawned player floats; Aswid_IsBatForm stays true in the ZDO, so every other client
|
/// respawned player floats; Aswid_IsBatForm stays true in the ZDO, so every other client
|
||||||
/// keeps drawing a bat over a body that is walking around as a person; and the 5% scale
|
/// keeps drawing a bat over a body that is walking around as a person; and the 5% scale
|
||||||
/// stays on the transform. Called from Aswid_BatDiesAsBat_Patch.
|
/// stays on the transform. Called from Aswid_BatDiesAsBat_Patch.
|
||||||
|
|
@ -682,12 +740,13 @@ namespace RacesOfValheim
|
||||||
if (nview != null && nview.IsValid())
|
if (nview != null && nview.IsValid())
|
||||||
{
|
{
|
||||||
nview.GetZDO().Set("Aswid_IsBatForm", false);
|
nview.GetZDO().Set("Aswid_IsBatForm", false);
|
||||||
nview.GetZDO().Set(ZDOVars.s_debugFly, false);
|
|
||||||
}
|
}
|
||||||
Traverse.Create(player).Field("m_debugFly").SetValue(false);
|
// Now, not when the destroyed model's OnDestroy gets round to it at the end of the frame.
|
||||||
|
BatFormBehavior.SetFlying(false);
|
||||||
|
|
||||||
player.transform.localScale = Vector3.one;
|
player.transform.localScale = Vector3.one;
|
||||||
|
|
||||||
|
lastBatEndTime = Time.time;
|
||||||
IsTransformed = false;
|
IsTransformed = false;
|
||||||
activeRules = null;
|
activeRules = null;
|
||||||
isTransformingSequence = false;
|
isTransformingSequence = false;
|
||||||
|
|
@ -787,6 +846,7 @@ namespace RacesOfValheim
|
||||||
}
|
}
|
||||||
Player.m_localPlayer.transform.localScale = endScale;
|
Player.m_localPlayer.transform.localScale = endScale;
|
||||||
|
|
||||||
|
lastBatEndTime = Time.time;
|
||||||
IsTransformed = false;
|
IsTransformed = false;
|
||||||
activeRules = null;
|
activeRules = null;
|
||||||
isTransformingSequence = false;
|
isTransformingSequence = false;
|
||||||
|
|
@ -1071,13 +1131,14 @@ namespace RacesOfValheim
|
||||||
private float damageTickTimer = 0f;
|
private float damageTickTimer = 0f;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The Vampiric Aura drains on its own, in every form, with no key to hold - but it does not
|
/// The Vampiric Aura drains on its own, with no key to hold (as a bat only once
|
||||||
|
/// BatAuraAllowed says so) - but it does not
|
||||||
/// distinguish traders from monsters, so it can execute Haldor/Hildir on approach. AuraEnabled
|
/// distinguish traders from monsters, so it can execute Haldor/Hildir on approach. AuraEnabled
|
||||||
/// (toggled with Devour on the same key) is the escape hatch for that.
|
/// (toggled with Devour on the same key) is the escape hatch for that.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private void HandleVampiricAura()
|
private void HandleVampiricAura()
|
||||||
{
|
{
|
||||||
if (!AuraEnabled)
|
if (!AuraEnabled || (IsBatForm() && !BatAuraAllowed(BossProgressionManager.GetCurrentProgressionState())))
|
||||||
{
|
{
|
||||||
damageTickTimer = 0f;
|
damageTickTimer = 0f;
|
||||||
return;
|
return;
|
||||||
|
|
@ -1090,6 +1151,24 @@ namespace RacesOfValheim
|
||||||
PerformLifeDrain();
|
PerformLifeDrain();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static bool IsBatForm()
|
||||||
|
{
|
||||||
|
return Player.m_localPlayer.GetSEMan().HaveStatusEffect("SE_BatForm".GetStableHashCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Whether the aura drains while the player is a bat. Off until the Queen by default: a bat
|
||||||
|
/// gliding over enemies that cannot reach it, draining them the whole way, was the "unfun
|
||||||
|
/// optimal way to play" Dissolution reported. The flag turns it back on for everyone; the
|
||||||
|
/// unlock state brings it back as a late-game reward, 0 meaning never.
|
||||||
|
/// </summary>
|
||||||
|
public static bool BatAuraAllowed(int state)
|
||||||
|
{
|
||||||
|
if (AswidConfig.AuraInBatForm.Value) return true;
|
||||||
|
int unlock = AswidConfig.BatAuraUnlockState.Value;
|
||||||
|
return unlock > 0 && state >= unlock;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>Half damage as a human, full as a bat, double as mist.</summary>
|
/// <summary>Half damage as a human, full as a bat, double as mist.</summary>
|
||||||
private float GetAuraFormMultiplier()
|
private float GetAuraFormMultiplier()
|
||||||
{
|
{
|
||||||
|
|
@ -1112,6 +1191,7 @@ namespace RacesOfValheim
|
||||||
|
|
||||||
int layerMask = LayerMask.GetMask("character", "character_net", "character_ghost");
|
int layerMask = LayerMask.GetMask("character", "character_net", "character_ghost");
|
||||||
var colliders = Physics.OverlapSphere(center, radius, layerMask);
|
var colliders = Physics.OverlapSphere(center, radius, layerMask);
|
||||||
|
bool hitCreature = false;
|
||||||
|
|
||||||
foreach (var col in colliders)
|
foreach (var col in colliders)
|
||||||
{
|
{
|
||||||
|
|
@ -1162,10 +1242,16 @@ namespace RacesOfValheim
|
||||||
// kill). ApplyDamage() skipped all of that: it edited the local copy of a
|
// kill). ApplyDamage() skipped all of that: it edited the local copy of a
|
||||||
// character we usually do not own, and the owner overwrote it on the next sync.
|
// character we usually do not own, and the owner overwrote it on the next sync.
|
||||||
c.Damage(hd);
|
c.Damage(hd);
|
||||||
|
hitCreature = true;
|
||||||
|
|
||||||
SpawnBloodVFX(c);
|
SpawnBloodVFX(c);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// The aura scales with Blood Magic but called Damage directly, so it never paid
|
||||||
|
// the skill back. Passive and always on, so it earns what the Skadi's Frost Aura
|
||||||
|
// does: a tenth of a hit per second of draining, once per tick, not per victim.
|
||||||
|
if (hitCreature) FormMelee.RaiseSkill(Skills.SkillType.BloodMagic, 0.1f * AswidConfig.AuraTickInterval.Value);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
|
@ -1271,7 +1357,10 @@ namespace RacesOfValheim
|
||||||
// up, but there used to be nothing to see either. Silence is what made
|
// up, but there used to be nothing to see either. Silence is what made
|
||||||
// a refused meal indistinguishable from a devour that never fired:
|
// a refused meal indistinguishable from a devour that never fired:
|
||||||
// vanilla's own "can't eat more" line, localized for free.
|
// vanilla's own "can't eat more" line, localized for free.
|
||||||
Player.m_localPlayer.Message(MessageHud.MessageType.TopLeft, "$msg_nomore");
|
// The token carries a $1 for the food's name, which vanilla's CanEat
|
||||||
|
// fills in; sent bare, players read "can't eat more $1".
|
||||||
|
Player.m_localPlayer.Message(MessageHud.MessageType.TopLeft,
|
||||||
|
Localization.instance.Localize("$msg_nomore", addedItem.m_shared.m_name));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
@ -1320,6 +1409,136 @@ namespace RacesOfValheim
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>Fader's Surtling form ends it, unless the setting keeps it for good.</summary>
|
||||||
|
public static bool HasFireWeakness(int state)
|
||||||
|
{
|
||||||
|
if (!AswidConfig.FireWeaknessEnabled.Value) return false;
|
||||||
|
return !(AswidConfig.FaderRemovesFireWeakness.Value && state >= 8);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static readonly int SunlightHash = "SE_AswidSunlight".GetStableHashCode();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The V Rising weakness: by day, under open sky, the sun saps the Aswid. Anything that
|
||||||
|
/// keeps the sky off you counts as shade - a roof by vanilla's own shelter test, a dungeon,
|
||||||
|
/// the Swamp's and Mistlands' gloom, the night, and the Aswid's own Eclipse, which makes
|
||||||
|
/// that spell an answer to the sun rather than only a damage boost.
|
||||||
|
/// </summary>
|
||||||
|
private void UpdateSunlight(float dt)
|
||||||
|
{
|
||||||
|
Player player = Player.m_localPlayer;
|
||||||
|
SEMan seman = player.GetSEMan();
|
||||||
|
|
||||||
|
bool exposed = InSunlight(player);
|
||||||
|
bool has = seman.HaveStatusEffect(SunlightHash);
|
||||||
|
|
||||||
|
if (!exposed)
|
||||||
|
{
|
||||||
|
if (has) seman.RemoveStatusEffect(SunlightHash, true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!has) seman.AddStatusEffect(SunlightHash, true);
|
||||||
|
(seman.GetStatusEffect(SunlightHash) as SE_AswidSunlight)?.Refresh();
|
||||||
|
|
||||||
|
// SetHealth rather than Damage or UseHealth: a burn every second should not stagger,
|
||||||
|
// interrupt a swing or flash the screen red each time. Never below the floor, so
|
||||||
|
// the sun can wear you down but never be what kills you.
|
||||||
|
float floor = player.GetMaxHealth() * AswidConfig.SunHealthFloor.Value;
|
||||||
|
float health = player.GetHealth();
|
||||||
|
float loss = AswidConfig.SunHealthLossPerSecond.Value * dt;
|
||||||
|
if (loss > 0f && health > floor)
|
||||||
|
{
|
||||||
|
player.SetHealth(Mathf.Max(floor, health - loss));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool InSunlight(Player player)
|
||||||
|
{
|
||||||
|
if (!AswidConfig.SunlightEnabled.Value) return false;
|
||||||
|
if (EnvMan.instance == null || !EnvMan.IsDay()) return false;
|
||||||
|
if (IsEclipseActive) return false;
|
||||||
|
if (player.InInterior() || player.InShelter()) return false;
|
||||||
|
|
||||||
|
Heightmap.Biome biome = player.GetCurrentBiome();
|
||||||
|
return biome != Heightmap.Biome.Swamp && biome != Heightmap.Biome.Mistlands;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static readonly int OpenSeaHash = "SE_AswidOpenSea".GetStableHashCode();
|
||||||
|
|
||||||
|
// How deep the water under an airborne Aswid has to be before it counts. Keeps a hop over
|
||||||
|
// a puddle or a swamp ditch from registering; a bat over a river or a lake still does.
|
||||||
|
private const float MinFlyOverDepth = 1f;
|
||||||
|
|
||||||
|
/// <summary>True while the local Aswid is out on the water, boat or not. Read by the camera sway.</summary>
|
||||||
|
public static bool OnWater { get; private set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Dagaz's running water: open water burns and drains an Aswid in it or over it, swimming
|
||||||
|
/// or flying - a bat cannot simply cross a lake or the sea. A boat carries you across, as
|
||||||
|
/// the lore allows: on board there is no burn and no drain, but the sea still turns your
|
||||||
|
/// stomach, so the camera keeps swaying.
|
||||||
|
/// </summary>
|
||||||
|
private void UpdateOpenSea(float dt)
|
||||||
|
{
|
||||||
|
Player player = Player.m_localPlayer;
|
||||||
|
SEMan seman = player.GetSEMan();
|
||||||
|
|
||||||
|
bool onBoat = OnBoat(player);
|
||||||
|
bool exposed = !onBoat && InOpenWater(player);
|
||||||
|
OnWater = AswidConfig.RunningWaterEnabled.Value && (exposed || (onBoat && BiomeAllowed(player)));
|
||||||
|
|
||||||
|
bool has = seman.HaveStatusEffect(OpenSeaHash);
|
||||||
|
if (!exposed)
|
||||||
|
{
|
||||||
|
if (has) seman.RemoveStatusEffect(OpenSeaHash, true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!has) seman.AddStatusEffect(OpenSeaHash, true);
|
||||||
|
|
||||||
|
float drain = AswidConfig.SeaStaminaDrainPerSecond.Value * dt;
|
||||||
|
if (drain > 0f) player.UseStamina(drain);
|
||||||
|
|
||||||
|
// SetHealth for the same reasons as the sun: no stagger, no flash each second.
|
||||||
|
float floor = player.GetMaxHealth() * AswidConfig.SeaHealthFloor.Value;
|
||||||
|
float health = player.GetHealth();
|
||||||
|
float loss = AswidConfig.SeaHealthLossPerSecond.Value * dt;
|
||||||
|
if (loss > 0f && health > floor)
|
||||||
|
{
|
||||||
|
player.SetHealth(Mathf.Max(floor, health - loss));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static bool OnBoat(Player player)
|
||||||
|
{
|
||||||
|
return player.GetStandingOnShip() != null || player.IsAttachedToShip() || player.GetControlledShip() != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>The Ocean-only setting, if on, limits everything here to the sea.</summary>
|
||||||
|
private static bool BiomeAllowed(Player player)
|
||||||
|
{
|
||||||
|
return !AswidConfig.WaterOceanOnly.Value || player.GetCurrentBiome() == Heightmap.Biome.Ocean;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// In water or over it. Valheim has one water plane for the sea, the rivers and the lakes
|
||||||
|
/// alike, so "the terrain under you is below the water level" finds all three. Swimming
|
||||||
|
/// counts wherever it happens. In the air it takes a metre of water below, so a jump over
|
||||||
|
/// a puddle does not; standing on anything solid - a dock, a bridge, a shallow bank you
|
||||||
|
/// are wading on - does not count, since the ground ray only sees terrain and would
|
||||||
|
/// otherwise read a dock as open water.
|
||||||
|
/// </summary>
|
||||||
|
private static bool InOpenWater(Player player)
|
||||||
|
{
|
||||||
|
if (!AswidConfig.RunningWaterEnabled.Value) return false;
|
||||||
|
if (!BiomeAllowed(player)) return false;
|
||||||
|
if (player.IsSwimming()) return true;
|
||||||
|
if (player.IsOnGround() || ZoneSystem.instance == null) return false;
|
||||||
|
|
||||||
|
float depth = ZoneSystem.instance.m_waterLevel - ZoneSystem.instance.GetGroundHeight(player.transform.position);
|
||||||
|
return depth >= MinFlyOverDepth;
|
||||||
|
}
|
||||||
|
|
||||||
private void UpdateAswidState()
|
private void UpdateAswidState()
|
||||||
{
|
{
|
||||||
AswidSpectralClaw.PurgeAll(Player.m_localPlayer); // feature disabled for now, see AswidSpectralClaw.cs
|
AswidSpectralClaw.PurgeAll(Player.m_localPlayer); // feature disabled for now, see AswidSpectralClaw.cs
|
||||||
|
|
@ -1344,6 +1563,12 @@ namespace RacesOfValheim
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>Max stamina the race adds on top of food, at the given progression state.</summary>
|
||||||
|
public static float GetStaminaBonus(int state)
|
||||||
|
{
|
||||||
|
return AswidConfig.BaseStaminaBonus.Value + AswidConfig.StaminaBonusPerState.Value * state;
|
||||||
|
}
|
||||||
|
|
||||||
public static bool IsAswid()
|
public static bool IsAswid()
|
||||||
{
|
{
|
||||||
return Player.m_localPlayer != null &&
|
return Player.m_localPlayer != null &&
|
||||||
|
|
|
||||||
|
|
@ -65,6 +65,45 @@ namespace RacesOfValheim
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Sunlight on an exposed Aswid. Its numbers are rewritten from AswidConfig every time
|
||||||
|
/// AswidRace.UpdateSunlight runs, so a slider moves them live; the health loss is not a stat
|
||||||
|
/// and is applied by that same tick.
|
||||||
|
/// </summary>
|
||||||
|
public class SE_AswidSunlight : SE_Stats
|
||||||
|
{
|
||||||
|
public override void Setup(Character character)
|
||||||
|
{
|
||||||
|
base.Setup(character);
|
||||||
|
name = "SE_AswidSunlight";
|
||||||
|
m_name = "$rov_se_aswid_sunlight_name";
|
||||||
|
m_tooltip = "$rov_se_aswid_sunlight_tooltip";
|
||||||
|
Refresh();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Refresh()
|
||||||
|
{
|
||||||
|
m_healthRegenMultiplier = 1f - AswidConfig.SunHealthRegenPenalty.Value;
|
||||||
|
m_staminaRegenMultiplier = 1f - AswidConfig.SunStaminaRegenPenalty.Value;
|
||||||
|
m_speedModifier = -AswidConfig.SunSpeedPenalty.Value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Open water under an Aswid off a boat. Only a marker: the burn and the drain are applied by
|
||||||
|
/// AswidRace.UpdateOpenSea, and the camera sway reads AswidRace.OnWater.
|
||||||
|
/// </summary>
|
||||||
|
public class SE_AswidOpenSea : SE_Stats
|
||||||
|
{
|
||||||
|
public override void Setup(Character character)
|
||||||
|
{
|
||||||
|
base.Setup(character);
|
||||||
|
name = "SE_AswidOpenSea";
|
||||||
|
m_name = "$rov_se_aswid_opensea_name";
|
||||||
|
m_tooltip = "$rov_se_aswid_opensea_tooltip";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public class SE_MistForm : SE_Stats
|
public class SE_MistForm : SE_Stats
|
||||||
{
|
{
|
||||||
public override void Setup(Character character)
|
public override void Setup(Character character)
|
||||||
|
|
@ -124,6 +163,16 @@ namespace RacesOfValheim
|
||||||
|
|
||||||
ItemManager.Instance.AddStatusEffect(new CustomStatusEffect(batForm, fixReference: false));
|
ItemManager.Instance.AddStatusEffect(new CustomStatusEffect(batForm, fixReference: false));
|
||||||
|
|
||||||
|
var sunlight = ScriptableObject.CreateInstance<SE_AswidSunlight>();
|
||||||
|
sunlight.name = "SE_AswidSunlight";
|
||||||
|
sunlight.m_icon = PrefabManager.Cache.GetPrefab<ItemDrop>("TrophySurtling")?.m_itemData.m_shared.m_icons[0];
|
||||||
|
ItemManager.Instance.AddStatusEffect(new CustomStatusEffect(sunlight, fixReference: false));
|
||||||
|
|
||||||
|
var openSea = ScriptableObject.CreateInstance<SE_AswidOpenSea>();
|
||||||
|
openSea.name = "SE_AswidOpenSea";
|
||||||
|
openSea.m_icon = PrefabManager.Cache.GetPrefab<ItemDrop>("TrophySerpent")?.m_itemData.m_shared.m_icons[0];
|
||||||
|
ItemManager.Instance.AddStatusEffect(new CustomStatusEffect(openSea, fixReference: false));
|
||||||
|
|
||||||
var mistForm = ScriptableObject.CreateInstance<SE_MistForm>();
|
var mistForm = ScriptableObject.CreateInstance<SE_MistForm>();
|
||||||
mistForm.name = "SE_MistForm";
|
mistForm.name = "SE_MistForm";
|
||||||
mistForm.m_icon = PrefabManager.Cache.GetPrefab<ItemDrop>("TrophyWraith")?.m_itemData.m_shared.m_icons[0];
|
mistForm.m_icon = PrefabManager.Cache.GetPrefab<ItemDrop>("TrophyWraith")?.m_itemData.m_shared.m_icons[0];
|
||||||
|
|
|
||||||
|
|
@ -58,6 +58,12 @@ namespace RacesOfValheim
|
||||||
private const float BaseEyeHeight = 0.181f;
|
private const float BaseEyeHeight = 0.181f;
|
||||||
private const float BaseEyeSeparation = 0.032f;
|
private const float BaseEyeSeparation = 0.032f;
|
||||||
|
|
||||||
|
// The borrowed socket at the size the Skeleton wears it, times the config multiplier, was
|
||||||
|
// two green blocks on the face; at half it was smaller than the painted eye underneath,
|
||||||
|
// which then showed round it. Applied before the multiplier, so a saved config keeps its
|
||||||
|
// meaning as "relative to the default".
|
||||||
|
private const float BaseEyeScale = 0.75f;
|
||||||
|
|
||||||
// ─── Race check ─────────────────────────────────────────────────────
|
// ─── Race check ─────────────────────────────────────────────────────
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -99,6 +105,10 @@ namespace RacesOfValheim
|
||||||
// built again rather than merely moved.
|
// built again rather than merely moved.
|
||||||
public string SourceModel = "";
|
public string SourceModel = "";
|
||||||
public bool FlatShader;
|
public bool FlatShader;
|
||||||
|
|
||||||
|
// Which body the base pose was measured for: the female face puts the eyes elsewhere
|
||||||
|
// (PlayerFace), so a change of body model is a rebuild too.
|
||||||
|
public bool Female;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>The pose an eye was authored at on the creature. Everything else is a delta on this.</summary>
|
/// <summary>The pose an eye was authored at on the creature. Everything else is a delta on this.</summary>
|
||||||
|
|
@ -180,7 +190,8 @@ namespace RacesOfValheim
|
||||||
EyeFrame existing = eyes.GetComponent<EyeFrame>();
|
EyeFrame existing = eyes.GetComponent<EyeFrame>();
|
||||||
if (existing == null ||
|
if (existing == null ||
|
||||||
existing.SourceModel != AswidConfig.EyeSourceModel.Value ||
|
existing.SourceModel != AswidConfig.EyeSourceModel.Value ||
|
||||||
existing.FlatShader != AswidConfig.EyeFlatColorShader.Value)
|
existing.FlatShader != AswidConfig.EyeFlatColorShader.Value ||
|
||||||
|
existing.Female != PlayerFace.IsFemale(player))
|
||||||
{
|
{
|
||||||
eyes.name = EyesName + "_Removed";
|
eyes.name = EyesName + "_Removed";
|
||||||
Object.Destroy(eyes.gameObject);
|
Object.Destroy(eyes.gameObject);
|
||||||
|
|
@ -309,9 +320,6 @@ namespace RacesOfValheim
|
||||||
|
|
||||||
float scale = GetPlayerScale(player) * toLocal;
|
float scale = GetPlayerScale(player) * toLocal;
|
||||||
|
|
||||||
Vector3 shift = frame.LocalForward * (AswidConfig.EyeForwardOffset.Value * scale)
|
|
||||||
+ frame.LocalUp * (AswidConfig.EyeHeightOffset.Value * scale);
|
|
||||||
|
|
||||||
for (int i = 0; i < holder.childCount; i++)
|
for (int i = 0; i < holder.childCount; i++)
|
||||||
{
|
{
|
||||||
Transform eye = holder.GetChild(i);
|
Transform eye = holder.GetChild(i);
|
||||||
|
|
@ -324,6 +332,16 @@ namespace RacesOfValheim
|
||||||
float side = Mathf.Sign(Vector3.Dot(authored.Position, frame.LocalRight));
|
float side = Mathf.Sign(Vector3.Dot(authored.Position, frame.LocalRight));
|
||||||
if (side == 0f) side = i == 0 ? -1f : 1f;
|
if (side == 0f) side = i == 0 ? -1f : 1f;
|
||||||
|
|
||||||
|
// This eye's hand corrections (RaceEyeTuning), on top of the race's own offsets.
|
||||||
|
RaceEyeTuning.Eye tuning = RaceEyeTuning.For("Aswid", player, side);
|
||||||
|
float forward = AswidConfig.EyeForwardOffset.Value + (tuning != null ? tuning.Forward : 0f);
|
||||||
|
float height = AswidConfig.EyeHeightOffset.Value + (tuning != null ? tuning.Height : 0f);
|
||||||
|
float separation = AswidConfig.EyeSeparationOffset.Value + (tuning != null ? tuning.Separation : 0f);
|
||||||
|
float size = AswidConfig.EyeSizeMultiplier.Value * (tuning != null ? tuning.Size : 1f);
|
||||||
|
|
||||||
|
Vector3 shift = frame.LocalForward * (forward * scale)
|
||||||
|
+ frame.LocalUp * (height * scale);
|
||||||
|
|
||||||
// YAW IS MIRRORED, the other two are not. Turning both eyes the same way on Y
|
// YAW IS MIRRORED, the other two are not. Turning both eyes the same way on Y
|
||||||
// makes the pair look sideways - both point off the same shoulder, because a face
|
// makes the pair look sideways - both point off the same shoulder, because a face
|
||||||
// is symmetric about its centre line and yaw is the axis that crosses it. Negating
|
// is symmetric about its centre line and yaw is the axis that crosses it. Negating
|
||||||
|
|
@ -332,15 +350,31 @@ namespace RacesOfValheim
|
||||||
//
|
//
|
||||||
// Pitch and roll are shared deliberately: both eyes looking up is a face looking
|
// Pitch and roll are shared deliberately: both eyes looking up is a face looking
|
||||||
// up, and mirroring either of those would cross them instead of aiming them.
|
// up, and mirroring either of those would cross them instead of aiming them.
|
||||||
|
//
|
||||||
|
// This twist is on the HEAD BONE's raw axes (it multiplies from the left), and on
|
||||||
|
// this rig those are not the face's: bone X points out of the face and bone Z
|
||||||
|
// sideways. The defaults were dialled in against that, so it stays as it is.
|
||||||
Quaternion twist = Quaternion.Euler(
|
Quaternion twist = Quaternion.Euler(
|
||||||
AswidConfig.EyeRotationX.Value,
|
AswidConfig.EyeRotationX.Value,
|
||||||
AswidConfig.EyeRotationY.Value * side,
|
AswidConfig.EyeRotationY.Value * side,
|
||||||
AswidConfig.EyeRotationZ.Value);
|
AswidConfig.EyeRotationZ.Value);
|
||||||
|
|
||||||
|
// The RaceEyeTuning corrections turn the eye on the FACE's axes instead: conjugated by
|
||||||
|
// the face frame, X tips it, Y turns it toward the temple and Z raises the outer
|
||||||
|
// corner, the same on both eyes. Added to the bone-axis twist above, X rolled the
|
||||||
|
// eyes and a mirrored Z tipped one up and the other down.
|
||||||
|
Quaternion nudge = Quaternion.identity;
|
||||||
|
if (tuning != null)
|
||||||
|
{
|
||||||
|
nudge = authored.Rotation
|
||||||
|
* Quaternion.Euler(tuning.RotX, tuning.RotY * side, tuning.RotZ * side)
|
||||||
|
* Quaternion.Inverse(authored.Rotation);
|
||||||
|
}
|
||||||
|
|
||||||
eye.localPosition = authored.Position + shift +
|
eye.localPosition = authored.Position + shift +
|
||||||
frame.LocalRight * (side * AswidConfig.EyeSeparationOffset.Value * scale);
|
frame.LocalRight * (side * separation * scale);
|
||||||
eye.localRotation = twist * authored.Rotation;
|
eye.localRotation = nudge * twist * authored.Rotation;
|
||||||
eye.localScale = authored.Scale * AswidConfig.EyeSizeMultiplier.Value;
|
eye.localScale = authored.Scale * size;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -424,6 +458,12 @@ namespace RacesOfValheim
|
||||||
MeasureFrame(player, headBone, frame);
|
MeasureFrame(player, headBone, frame);
|
||||||
frame.SourceModel = modelName;
|
frame.SourceModel = modelName;
|
||||||
frame.FlatShader = AswidConfig.EyeFlatColorShader.Value;
|
frame.FlatShader = AswidConfig.EyeFlatColorShader.Value;
|
||||||
|
frame.Female = PlayerFace.IsFemale(player);
|
||||||
|
|
||||||
|
float baseHeight = BaseEyeHeight;
|
||||||
|
float baseSeparation = BaseEyeSeparation;
|
||||||
|
float baseSize = BaseEyeScale;
|
||||||
|
PlayerFace.AdjustEyes(player, ref baseHeight, ref baseSeparation, ref baseSize);
|
||||||
|
|
||||||
// canonicalToFrame turns "face forward, as authored" into "face forward, on THIS
|
// canonicalToFrame turns "face forward, as authored" into "face forward, on THIS
|
||||||
// rig's own axes" - the rotation that carries the ordinary (X,Y,Z) convention onto
|
// rig's own axes" - the rotation that carries the ordinary (X,Y,Z) convention onto
|
||||||
|
|
@ -458,8 +498,8 @@ namespace RacesOfValheim
|
||||||
float toLocal = 1f / headBone.lossyScale.x;
|
float toLocal = 1f / headBone.lossyScale.x;
|
||||||
|
|
||||||
Vector3 basePosition = frame.LocalForward * (BaseEyeForward * toLocal)
|
Vector3 basePosition = frame.LocalForward * (BaseEyeForward * toLocal)
|
||||||
+ frame.LocalUp * (BaseEyeHeight * toLocal)
|
+ frame.LocalUp * (baseHeight * toLocal)
|
||||||
+ frame.LocalRight * (side * BaseEyeSeparation * toLocal);
|
+ frame.LocalRight * (side * baseSeparation * toLocal);
|
||||||
|
|
||||||
// The socket's own authored tilt is skipped for the same reason its position is -
|
// The socket's own authored tilt is skipped for the same reason its position is -
|
||||||
// canonicalToFrame alone (face forward, on this rig's axes) is what the config's
|
// canonicalToFrame alone (face forward, on this rig's axes) is what the config's
|
||||||
|
|
@ -481,7 +521,7 @@ namespace RacesOfValheim
|
||||||
// this object at on a real skeleton. Divided into the new parent's scale, the pair
|
// this object at on a real skeleton. Divided into the new parent's scale, the pair
|
||||||
// lands at exactly the size vanilla wears them, which is the whole point of
|
// lands at exactly the size vanilla wears them, which is the whole point of
|
||||||
// borrowing them instead of drawing spheres.
|
// borrowing them instead of drawing spheres.
|
||||||
Vector3 baseScale = source.lossyScale * toLocal;
|
Vector3 baseScale = source.lossyScale * (toLocal * baseSize);
|
||||||
|
|
||||||
// Remembered before anything moves it, because everything the config does is
|
// Remembered before anything moves it, because everything the config does is
|
||||||
// expressed as a delta on this.
|
// expressed as a delta on this.
|
||||||
|
|
|
||||||
|
|
@ -1,86 +1,169 @@
|
||||||
using HarmonyLib;
|
using HarmonyLib;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using Jotunn.Managers;
|
|
||||||
|
|
||||||
namespace RacesOfValheim
|
namespace RacesOfValheim
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The bat's flight, held on for as long as the worn model exists.
|
/// The bat's flight, held on for as long as the worn model exists.
|
||||||
///
|
///
|
||||||
/// Debug fly has two halves, and this used to write only one. The field Player.m_debugFly is
|
/// The bat flies on Character.m_flying and is steered by DirectedFlightPatch, the same
|
||||||
/// what the local player's own physics reads; ZDOVars.s_debugFly is what every OTHER client
|
/// controls as the Skadi's drake; this class only hands over the bat's own numbers and keeps
|
||||||
/// reads, because Character.IsDebugFlying consults the ZDO whenever it is not the owner. With
|
/// the flag up. It used to fly on vanilla's debug-fly flag, which ignored carry weight, cost
|
||||||
/// only the field written, a bat flew on its own screen and fell, walked and swam on everyone
|
/// nothing, moved at 50 m/s and made every monster blind to the player - the Discord reports
|
||||||
/// else's - the fault WarVultureMount.SetFlying already names in its own summary. Both halves
|
/// that started the 2026 rebalance.
|
||||||
/// go through SetFlying below now, so there is one place that can ever get it wrong again.
|
|
||||||
///
|
///
|
||||||
/// Writing the ZDO every frame is not network spam: ZDO.Set(int, bool) bottoms out in
|
/// Other clients learn the bat is airborne from Aswid_IsBatForm in the ZDO, which
|
||||||
/// ZDOExtraData.Set, which returns false when the value is unchanged, and only a true return
|
/// Aswid_MultiplayerVisuals_Patch mirrors into their copy's m_flying.
|
||||||
/// bumps the data revision. Read out of the assembly rather than assumed, because "every frame"
|
///
|
||||||
/// deserved the check.
|
/// FREE FLIGHT. A player who picks it (or a server that forces it, AswidConfig.UsesFreeBatFlight)
|
||||||
|
/// gets the old flight back: vanilla's debug fly, both halves (the field for the local physics,
|
||||||
|
/// s_debugFly in the ZDO for everyone else), and no DirectedFlight. The mode is read once, when
|
||||||
|
/// the form goes up. AswidBatForm keeps monsters seeing and hurting a free-flying bat.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class BatFormBehavior : MonoBehaviour
|
public class BatFormBehavior : MonoBehaviour, IDirectedFlyer
|
||||||
{
|
{
|
||||||
|
private static readonly System.Reflection.FieldInfo FlyingField =
|
||||||
|
AccessTools.Field(typeof(Character), "m_flying");
|
||||||
private static readonly System.Reflection.FieldInfo DebugFlyField =
|
private static readonly System.Reflection.FieldInfo DebugFlyField =
|
||||||
AccessTools.Field(typeof(Player), "m_debugFly");
|
AccessTools.Field(typeof(Player), "m_debugFly");
|
||||||
|
|
||||||
private Animator anim;
|
private Animator anim;
|
||||||
private AswidProgression.FormRules formRules;
|
private AswidProgression.FormRules formRules;
|
||||||
|
private float startTime;
|
||||||
|
private bool warnedTooHeavy;
|
||||||
|
private bool expired;
|
||||||
|
private bool free;
|
||||||
|
|
||||||
public void Initialize(AswidProgression.FormRules rules)
|
public void Initialize(AswidProgression.FormRules rules)
|
||||||
{
|
{
|
||||||
this.formRules = rules;
|
this.formRules = rules;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ─── IDirectedFlyer ─────────────────────────────────────────────────────
|
||||||
|
// A bat is never grounded on purpose: it flies for as long as the form lasts.
|
||||||
|
public bool IsFlying => true;
|
||||||
|
public float LastPoweredTime { get; set; }
|
||||||
|
public float TurnSpeed => AswidConfig.BatTurnSpeed.Value;
|
||||||
|
public float GlideSpeed => AswidConfig.BatGlideSpeed.Value;
|
||||||
|
public float BoostSpeed => AswidConfig.BatBoostSpeed.Value;
|
||||||
|
public float SprintSpeed => AswidConfig.BatSprintSpeed.Value;
|
||||||
|
public float ReverseSpeed => AswidConfig.BatReverseSpeed.Value;
|
||||||
|
public float LiftoffSpeed => AswidConfig.BatLiftoffSpeed.Value;
|
||||||
|
public float HoverSeconds => AswidConfig.BatHoverSeconds.Value;
|
||||||
|
public float PoweredStaminaPerSecond => AswidConfig.BatPoweredStaminaPerSecond.Value * EncumberedCostFactor();
|
||||||
|
public float SprintStaminaPerSecond => AswidConfig.BatSprintStaminaPerSecond.Value * EncumberedCostFactor();
|
||||||
|
public bool CanPower => !(IsEncumbered() && AswidConfig.BatEncumbered.Value == AswidConfig.EncumberedMode.Blocked);
|
||||||
|
|
||||||
|
private static bool IsEncumbered()
|
||||||
|
{
|
||||||
|
return Player.m_localPlayer != null && Player.m_localPlayer.IsEncumbered();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static float EncumberedCostFactor()
|
||||||
|
{
|
||||||
|
return IsEncumbered() ? 1f + AswidConfig.BatEncumberedExtraCost.Value : 1f;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The form's lifetime in seconds at the current state, or 0 for no limit. The per-state
|
||||||
|
/// bonus is Dissolution's "scales with boss progression", and only means anything on top
|
||||||
|
/// of a base limit.
|
||||||
|
/// </summary>
|
||||||
|
public static float MaxDuration()
|
||||||
|
{
|
||||||
|
float max = AswidConfig.BatMaxDuration.Value;
|
||||||
|
if (max <= 0f) return 0f;
|
||||||
|
return max + AswidConfig.BatDurationPerState.Value * BossProgressionManager.GetCurrentProgressionState();
|
||||||
|
}
|
||||||
|
|
||||||
private void Start()
|
private void Start()
|
||||||
{
|
{
|
||||||
anim = GetComponentInChildren<Animator>();
|
anim = GetComponentInChildren<Animator>();
|
||||||
SetFlying(true);
|
startTime = Time.time;
|
||||||
|
LastPoweredTime = Time.time;
|
||||||
|
free = AswidConfig.UsesFreeBatFlight();
|
||||||
|
if (!free) DirectedFlight.Register(this);
|
||||||
|
Hold();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Update()
|
private void Update()
|
||||||
{
|
{
|
||||||
if (Player.m_localPlayer == null || Player.m_localPlayer.IsDead()) return;
|
Player player = Player.m_localPlayer;
|
||||||
|
if (player == null || player.IsDead()) return;
|
||||||
|
|
||||||
// Ensure flight remains on continuously
|
// Held every frame rather than set once, for the same reason the debug-fly flag was:
|
||||||
SetFlying(true);
|
// anything that clears it mid-form (a vanilla reset, another mod) would drop the bat
|
||||||
|
// into walking with the model still on.
|
||||||
|
Hold();
|
||||||
|
|
||||||
|
// Free Flight ignores weight, so only Stamina Flight warns about it.
|
||||||
|
if (!free)
|
||||||
|
{
|
||||||
|
if (!CanPower && !warnedTooHeavy)
|
||||||
|
{
|
||||||
|
warnedTooHeavy = true;
|
||||||
|
player.Message(MessageHud.MessageType.Center, ModText.Get("rov_msg_aswid_bat_too_heavy_to_beat"));
|
||||||
|
}
|
||||||
|
else if (CanPower)
|
||||||
|
{
|
||||||
|
warnedTooHeavy = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
float max = MaxDuration();
|
||||||
|
if (max > 0f && !expired && Time.time - startTime >= max && AswidRace.Instance != null)
|
||||||
|
{
|
||||||
|
expired = true;
|
||||||
|
player.Message(MessageHud.MessageType.Center, ModText.Get("rov_msg_aswid_bat_form_fades"));
|
||||||
|
AswidRace.Instance.ForceRevert();
|
||||||
|
}
|
||||||
|
|
||||||
// Sync Animator
|
|
||||||
if (anim != null)
|
if (anim != null)
|
||||||
{
|
{
|
||||||
Vector3 vel = Player.m_localPlayer.GetVelocity();
|
Vector3 vel = player.GetVelocity();
|
||||||
vel.y = 0f;
|
vel.y = 0f;
|
||||||
float speed = vel.magnitude;
|
anim.SetFloat("forward_speed", vel.magnitude);
|
||||||
|
|
||||||
// Bats don't necessarily have a complex animator like players,
|
|
||||||
// but if they do have a speed or flying parameter, we set it here.
|
|
||||||
anim.SetFloat("forward_speed", speed);
|
|
||||||
anim.SetBool("flying", true);
|
anim.SetBool("flying", true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnDestroy()
|
private void OnDestroy()
|
||||||
{
|
{
|
||||||
|
DirectedFlight.Unregister(this);
|
||||||
SetFlying(false);
|
SetFlying(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void Hold()
|
||||||
|
{
|
||||||
|
if (free) SetDebugFly(true);
|
||||||
|
else SetFlying(true);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Both halves of debug fly, always together. The field write survives a missing or invalid
|
/// The local half of Stamina Flight. The remote half is the Aswid_IsBatForm ZDO flag
|
||||||
/// ZNetView on purpose: without it a bat whose networking went away mid-flight would keep
|
/// AswidRace already writes, so there is nothing to replicate here. Turning it off also
|
||||||
/// flying on foot forever, which is the worse of the two failures.
|
/// turns debug fly off, so every exit path ends both flights whichever one was up.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private static void SetFlying(bool flying)
|
public static void SetFlying(bool flying)
|
||||||
{
|
{
|
||||||
Player player = Player.m_localPlayer;
|
Player player = Player.m_localPlayer;
|
||||||
if (player == null) return;
|
if (player == null) return;
|
||||||
|
if (FlyingField != null) FlyingField.SetValue(player, flying);
|
||||||
|
if (!flying) SetDebugFly(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Both halves of debug fly, for Free Flight. The ZDO write every frame is not network
|
||||||
|
/// spam: ZDO.Set returns early when the value is unchanged.
|
||||||
|
/// </summary>
|
||||||
|
private static void SetDebugFly(bool flying)
|
||||||
|
{
|
||||||
|
Player player = Player.m_localPlayer;
|
||||||
|
if (player == null) return;
|
||||||
if (DebugFlyField != null) DebugFlyField.SetValue(player, flying);
|
if (DebugFlyField != null) DebugFlyField.SetValue(player, flying);
|
||||||
|
|
||||||
ZNetView nview = player.GetComponent<ZNetView>();
|
ZNetView nview = player.GetComponent<ZNetView>();
|
||||||
if (nview != null && nview.IsValid() && nview.IsOwner())
|
if (nview != null && nview.IsValid() && nview.IsOwner()) nview.GetZDO().Set(ZDOVars.s_debugFly, flying);
|
||||||
{
|
|
||||||
nview.GetZDO().Set(ZDOVars.s_debugFly, flying);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
BIN
JotunnModStub/Audio/trolsbuilding.ogg
Normal file
BIN
JotunnModStub/Audio/trolsdeath.ogg
Normal file
|
|
@ -218,6 +218,7 @@ namespace RacesOfValheim
|
||||||
}
|
}
|
||||||
|
|
||||||
prefab.transform.localScale = Vector3.one * TableScale;
|
prefab.transform.localScale = Vector3.one * TableScale;
|
||||||
|
Dress(prefab, family);
|
||||||
|
|
||||||
ServantTableBehaviour table = prefab.AddComponent<ServantTableBehaviour>();
|
ServantTableBehaviour table = prefab.AddComponent<ServantTableBehaviour>();
|
||||||
table.m_switch = prefab.AddComponent<Switch>();
|
table.m_switch = prefab.AddComponent<Switch>();
|
||||||
|
|
@ -255,6 +256,65 @@ namespace RacesOfValheim
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// The look, in the table's own space BEFORE TableScale, so sizes are divided by it to come out
|
||||||
|
// in real metres. The cover lies where the map was: x -2.06 to 0.62, read off the mesh. Its top
|
||||||
|
// is the Dvergar bank's PileHeight, on the same vanilla mesh; the mesh's own height is no use
|
||||||
|
// here, since the writing desk stands taller than the map.
|
||||||
|
private const float CoverTop = 1.05f;
|
||||||
|
private static readonly Vector3 TradeSpot = new Vector3(-0.75f, CoverTop, 0.2f);
|
||||||
|
private static readonly Vector3 SkullSpot = new Vector3(-1.55f, CoverTop, 0.35f);
|
||||||
|
private const float AnvilSize = 0.75f;
|
||||||
|
private const float MealSize = 0.6f;
|
||||||
|
private const float SkullSize = 0.45f;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The map painted over - a sheet of chainmail for the smith, a red and white tablecloth for the
|
||||||
|
/// cook - with the trade's own work on it (an anvil, a meal) and a skeleton's skull beside it.
|
||||||
|
/// </summary>
|
||||||
|
private static void Dress(GameObject prefab, ButlerFamily family)
|
||||||
|
{
|
||||||
|
bool forge = family == ButlerFamily.Forge;
|
||||||
|
LayCover(prefab, forge ? "SmithMail" : "CookCloth", metal: forge);
|
||||||
|
|
||||||
|
float metres = 1f / TableScale;
|
||||||
|
if (forge)
|
||||||
|
{
|
||||||
|
ModelBorrow.Attach(prefab.transform, "TableAnvil", "forge_ext2",
|
||||||
|
TradeSpot, Quaternion.identity, AnvilSize * metres, "Butler", activeOnly: true);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ModelBorrow.Attach(prefab.transform, "TableMeal", "MeatPlatter",
|
||||||
|
TradeSpot, Quaternion.identity, MealSize * metres, "Butler", activeOnly: true);
|
||||||
|
}
|
||||||
|
ModelBorrow.Attach(prefab.transform, "TableSkull", "TrophySkeleton",
|
||||||
|
SkullSpot, Quaternion.Euler(0f, -150f, 0f), SkullSize * metres, "Butler", activeOnly: true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The cartography table's own textures with the map painted over, offline:
|
||||||
|
/// scripts/paint_cook_cloth.py (CookCloth) and scripts/paint_smith_mail.py (SmithMail). Each set
|
||||||
|
/// has its own worn texture for a damaged table (a stained cloth, rusted mail) and its own normal
|
||||||
|
/// map, so the coastline's relief does not show through. The mail also brings a metallic map,
|
||||||
|
/// which is what makes the rings shine; the cloth keeps vanilla's, which is metal nowhere.
|
||||||
|
/// </summary>
|
||||||
|
private static void LayCover(GameObject prefab, string set, bool metal)
|
||||||
|
{
|
||||||
|
var cover = new System.Collections.Generic.Dictionary<string, Texture>();
|
||||||
|
AddCover(cover, "Cartographer_d", set + "_d.png", false);
|
||||||
|
AddCover(cover, "Cartographer_worn_d", set + "_worn_d.png", false);
|
||||||
|
AddCover(cover, "Cartographer_n", set + "_n.png", true);
|
||||||
|
if (metal) AddCover(cover, "Cartographer_m", set + "_m.png", true);
|
||||||
|
PieceLook.Retexture(prefab.transform, cover);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void AddCover(System.Collections.Generic.Dictionary<string, Texture> cover,
|
||||||
|
string vanilla, string resource, bool linear)
|
||||||
|
{
|
||||||
|
Texture2D texture = PieceLook.LoadTexture(resource, linear);
|
||||||
|
if (texture != null) cover[vanilla] = texture;
|
||||||
|
}
|
||||||
|
|
||||||
public static void EnsureKnown(Player player)
|
public static void EnsureKnown(Player player)
|
||||||
{
|
{
|
||||||
if (player == null) return;
|
if (player == null) return;
|
||||||
|
|
|
||||||
|
|
@ -270,7 +270,11 @@ namespace RacesOfValheim
|
||||||
else if (Time.time >= m_nextFightScan)
|
else if (Time.time >= m_nextFightScan)
|
||||||
{
|
{
|
||||||
m_nextFightScan = Time.time + FightScanInterval;
|
m_nextFightScan = Time.time + FightScanInterval;
|
||||||
if (BaseAI.FindClosestEnemy(m_character, transform.position, FightRange) != null)
|
// FindClosestEnemy takes its first match at ANY distance (it only compares against
|
||||||
|
// maxDistance once it holds one), so with a deer anywhere in the loaded zones it never
|
||||||
|
// returned null and vanilla kept the tick: the worker idled about instead of working.
|
||||||
|
Character enemy = BaseAI.FindClosestEnemy(m_character, transform.position, FightRange);
|
||||||
|
if (enemy != null && Vector3.Distance(enemy.transform.position, transform.position) <= FightRange)
|
||||||
{
|
{
|
||||||
m_fightUntil = Time.time + FightLinger;
|
m_fightUntil = Time.time + FightLinger;
|
||||||
}
|
}
|
||||||
|
|
@ -359,8 +363,22 @@ namespace RacesOfValheim
|
||||||
Scan(anchor.Value);
|
Scan(anchor.Value);
|
||||||
ExpirePenalties();
|
ExpirePenalties();
|
||||||
|
|
||||||
if (m_payload.Count > 0) { m_job = PlanDelivery(anchor.Value); return; }
|
// A delivery gets its own clock like any other job. Returning early here left it with the
|
||||||
|
// load's deadline: a slow trip, or a fight on the way, made it late before it started, and
|
||||||
|
// it timed out and was planned again on every tick, frozen with the goods in hand.
|
||||||
|
Job job;
|
||||||
|
if (m_payload.Count > 0) job = PlanDelivery(anchor.Value);
|
||||||
|
else job = PlanWork();
|
||||||
|
|
||||||
|
if (job != null && (m_job == null || m_job.Kind != job.Kind || m_job.Target != job.Target))
|
||||||
|
{
|
||||||
|
m_jobDeadline = Time.time + JobTimeout;
|
||||||
|
}
|
||||||
|
m_job = job;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Job PlanWork()
|
||||||
|
{
|
||||||
// The forge has no clock: a smelter holds its ore indefinitely and puts its own output on
|
// The forge has no clock: a smelter holds its ore indefinitely and puts its own output on
|
||||||
// the floor, so PlanRescue would ask a question whose answer is always no. The smith is a
|
// the floor, so PlanRescue would ask a question whose answer is always no. The smith is a
|
||||||
// four-state machine and the cook is a five-state one, and that is the whole of the
|
// four-state machine and the cook is a five-state one, and that is the whole of the
|
||||||
|
|
@ -372,13 +390,7 @@ namespace RacesOfValheim
|
||||||
// in return, because FuelWanted is zero for a station with no work: an empty furnace asks
|
// in return, because FuelWanted is zero for a station with no work: an empty furnace asks
|
||||||
// for no coal, gets filled, and only then becomes worth stoking.
|
// for no coal, gets filled, and only then becomes worth stoking.
|
||||||
Job job = m_family == ButlerFamily.Kitchen ? PlanRescue() : null;
|
Job job = m_family == ButlerFamily.Kitchen ? PlanRescue() : null;
|
||||||
job = job ?? PlanCollect() ?? PlanFuel() ?? PlanLoad();
|
return job ?? PlanCollect() ?? PlanFuel() ?? PlanLoad();
|
||||||
|
|
||||||
if (job != null && (m_job == null || m_job.Kind != job.Kind || m_job.Target != job.Target))
|
|
||||||
{
|
|
||||||
m_jobDeadline = Time.time + JobTimeout;
|
|
||||||
}
|
|
||||||
m_job = job;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -630,8 +642,10 @@ namespace RacesOfValheim
|
||||||
// coal, so gating the delivery on free slots sent the servant back to the chest with
|
// coal, so gating the delivery on free slots sent the servant back to the chest with
|
||||||
// the coal it had just fetched - and then PlanFuel sent it out for the same coal again,
|
// the coal it had just fetched - and then PlanFuel sent it out for the same coal again,
|
||||||
// forever. AcceptsAnything already asks the right question of both doors.
|
// forever. AcceptsAnything already asks the right question of both doors.
|
||||||
|
// A station it could not reach is in the penalty box: asking it again straight away
|
||||||
|
// is the same failed trip.
|
||||||
ButlerStation station = StationById(target);
|
ButlerStation station = StationById(target);
|
||||||
if (station != null && station.Alive && station.Operable && AcceptsAnything(station))
|
if (station != null && station.Alive && station.Operable && AcceptsAnything(station) && !IsPenalised(target))
|
||||||
{
|
{
|
||||||
return new Job
|
return new Job
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -143,7 +143,8 @@ namespace RacesOfValheim
|
||||||
string status = servant.Status;
|
string status = servant.Status;
|
||||||
if (string.IsNullOrEmpty(status)) status = ModText.Get("rov_hover_butler_waiting");
|
if (string.IsNullOrEmpty(status)) status = ModText.Get("rov_hover_butler_waiting");
|
||||||
|
|
||||||
return m_title + "\n" + status;
|
// m_title is a $token, and a hover text goes to the HUD as it is: nothing localizes it later.
|
||||||
|
return Localization.instance.Localize(m_title) + "\n" + status;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
|
||||||
|
|
@ -31,6 +31,8 @@ namespace RacesOfValheim
|
||||||
"Aswid - Eyes",
|
"Aswid - Eyes",
|
||||||
"Fenrir - Appearance",
|
"Fenrir - Appearance",
|
||||||
"Skeleton - Visuals",
|
"Skeleton - Visuals",
|
||||||
|
// Food and stamina for a Skeleton who wants them: each only gives up an advantage.
|
||||||
|
"Skeleton - Mortal Habits",
|
||||||
"Sverm - Dorsal Spines",
|
"Sverm - Dorsal Spines",
|
||||||
"Sverm - Emberform",
|
"Sverm - Emberform",
|
||||||
"Trol - Appearance",
|
"Trol - Appearance",
|
||||||
|
|
@ -42,9 +44,13 @@ namespace RacesOfValheim
|
||||||
private static readonly string[] LocalKeyParts =
|
private static readonly string[] LocalKeyParts =
|
||||||
{
|
{
|
||||||
"marker light", "tint", "colour", "color", "glow", "swarm scale", "log rounds", "debug",
|
"marker light", "tint", "colour", "color", "glow", "swarm scale", "log rounds", "debug",
|
||||||
|
// The Aswid's seasick camera: motion makes some players ill, so a server cannot force it.
|
||||||
|
"camera sway",
|
||||||
// Each player picks their own True Form: a player model mod (VRM and the like) breaks
|
// Each player picks their own True Form: a player model mod (VRM and the like) breaks
|
||||||
// under the troll costume, so a server cannot be allowed to force the costume on.
|
// under the troll costume, so a server cannot be allowed to force the costume on.
|
||||||
"legacy true form",
|
"legacy true form",
|
||||||
|
// The player's own pick of bat flight; the synced Bat Flight Rule can override it.
|
||||||
|
"free bat flight",
|
||||||
};
|
};
|
||||||
|
|
||||||
public static void Apply(ConfigFile config)
|
public static void Apply(ConfigFile config)
|
||||||
|
|
|
||||||
32
JotunnModStub/DebugConfig.cs
Normal file
|
|
@ -0,0 +1,32 @@
|
||||||
|
using UnityEngine;
|
||||||
|
using BepInEx.Configuration;
|
||||||
|
|
||||||
|
namespace RacesOfValheim
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The mod-wide debug switches, in one "Debug" section rather than one per race. Bound last
|
||||||
|
/// from RacesOfValheim.Awake(), so Configuration Manager lists the section at the bottom.
|
||||||
|
///
|
||||||
|
/// Every entry stays local (never synced from the server): ConfigSync leaves KeyboardShortcut
|
||||||
|
/// entries and any key containing "debug" alone, so keep "Debug" in the key names.
|
||||||
|
/// </summary>
|
||||||
|
public static class DebugConfig
|
||||||
|
{
|
||||||
|
public static ConfigEntry<bool> EnableDebugKey;
|
||||||
|
public static ConfigEntry<KeyboardShortcut> DebugKey;
|
||||||
|
public static ConfigEntry<bool> LogFormHits;
|
||||||
|
|
||||||
|
public static void Bind(ConfigFile config)
|
||||||
|
{
|
||||||
|
const string section = "Debug";
|
||||||
|
EnableDebugKey = config.Bind(section, "Debug: Enable Debug Key", false,
|
||||||
|
new ConfigDescription("Turns on the debug key below. Leave it off unless you are sending a bug report."));
|
||||||
|
DebugKey = config.Bind(section, "Debug Key", new KeyboardShortcut(KeyCode.F8),
|
||||||
|
new ConfigDescription("Toggles the melee reach readout (top left and log) and writes what the Alfar drones and the camera's target are doing to the log."));
|
||||||
|
// Was "Fenrir - Debug" / "Debug: Log Form Hits" until v1.6.10. It covers the Skadi,
|
||||||
|
// Sverm and Trol forms too (FormMelee.LogHit), so it moved here.
|
||||||
|
LogFormHits = config.Bind(section, "Debug: Log Form Hits", false,
|
||||||
|
new ConfigDescription("Writes one log line per form claw, bite or swing: what was in reach, what it hit, and why anything was skipped. For bug reports about attacks that do no damage."));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
263
JotunnModStub/DirectedFlight.cs
Normal file
|
|
@ -0,0 +1,263 @@
|
||||||
|
using System.Reflection;
|
||||||
|
using HarmonyLib;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace RacesOfValheim
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// A form that flies on Character's native flying-creature movement (m_flying) and is steered
|
||||||
|
/// by DirectedFlightPatch. The Skadi's drakes were the first; the Aswid's bat moved onto it from
|
||||||
|
/// vanilla's debug-fly flag in the 2026 rebalance, so the two share one set of controls and
|
||||||
|
/// differ only in the numbers each form hands back here.
|
||||||
|
/// </summary>
|
||||||
|
public interface IDirectedFlyer
|
||||||
|
{
|
||||||
|
/// <summary>False while the form is on the ground on purpose (a landed drake).</summary>
|
||||||
|
bool IsFlying { get; }
|
||||||
|
|
||||||
|
/// <summary>Time.time of the last powered or grounded moment; the hover window counts from it.</summary>
|
||||||
|
float LastPoweredTime { get; set; }
|
||||||
|
|
||||||
|
float TurnSpeed { get; }
|
||||||
|
float GlideSpeed { get; }
|
||||||
|
float BoostSpeed { get; }
|
||||||
|
float SprintSpeed { get; }
|
||||||
|
float ReverseSpeed { get; }
|
||||||
|
float LiftoffSpeed { get; }
|
||||||
|
float HoverSeconds { get; }
|
||||||
|
|
||||||
|
/// <summary>Stamina per second for powered flight (forward or reverse). 0 is free.</summary>
|
||||||
|
float PoweredStaminaPerSecond { get; }
|
||||||
|
|
||||||
|
/// <summary>Stamina per second for the sprint, charged on top of the powered cost.</summary>
|
||||||
|
float SprintStaminaPerSecond { get; }
|
||||||
|
|
||||||
|
/// <summary>False forbids powered flight outright, so the form can only glide and sink.</summary>
|
||||||
|
bool CanPower { get; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class DirectedFlight
|
||||||
|
{
|
||||||
|
/// <summary>The local player's flying form, if any. Set and cleared by the form itself.</summary>
|
||||||
|
public static IDirectedFlyer Active { get; private set; }
|
||||||
|
|
||||||
|
public static void Register(IDirectedFlyer flyer) { Active = flyer; }
|
||||||
|
|
||||||
|
public static void Unregister(IDirectedFlyer flyer)
|
||||||
|
{
|
||||||
|
if (Active == flyer) Active = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>The active form, only while it is actually in the air.</summary>
|
||||||
|
public static IDirectedFlyer Flying => Active != null && Active.IsFlying ? Active : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// The form flips the player into Character's native flying-creature movement (m_flying = true)
|
||||||
|
// instead of the debug-fly noclip, which lets us feed it a full 3D move direction.
|
||||||
|
// Character.UpdateFlying normally reads whatever m_moveDir the vanilla input pipeline last
|
||||||
|
// wrote (ground-plane WASD relative to camera yaw only); this patch overwrites it every frame
|
||||||
|
// with the camera's actual look direction (pitch included) so the player always glides toward
|
||||||
|
// wherever the mouse is aiming, with W powering forward, Shift spending stamina for a burst of
|
||||||
|
// speed, and S beating backwards away from whatever you are looking at.
|
||||||
|
[HarmonyPatch(typeof(Character), "UpdateFlying")]
|
||||||
|
public static class DirectedFlightPatch
|
||||||
|
{
|
||||||
|
// Tangent of the unpowered descent angle: 0.4 sinks at roughly 22 degrees below level.
|
||||||
|
private const float DESCENT_SLOPE = 0.4f;
|
||||||
|
// How much of the aim heading survives the climb out of water. Mostly up, with enough
|
||||||
|
// forward in it that the player still chooses which shore they surface towards.
|
||||||
|
private const float LIFTOFF_HEADING_BLEND = 0.35f;
|
||||||
|
// How far the left stick has to be pushed before it counts as W or S.
|
||||||
|
private const float StickThreshold = 0.5f;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// True while the local player is beating backwards this frame. Read by
|
||||||
|
/// SkadiReverseFacingPatch, which keeps the body pointed at the camera while it happens.
|
||||||
|
/// </summary>
|
||||||
|
public static bool Reversing { get; private set; }
|
||||||
|
|
||||||
|
// The September 2026 hotfix dropped the bool parameter from ZInput.GetJoyLeftStickY.
|
||||||
|
// A direct call binds to whichever signature we compiled against and throws
|
||||||
|
// MissingMethodException on the other, so resolve it at runtime and accept either.
|
||||||
|
private static readonly MethodInfo JoyLeftStickYMethod =
|
||||||
|
AccessTools.Method(typeof(ZInput), "GetJoyLeftStickY", new System.Type[0]) ??
|
||||||
|
AccessTools.Method(typeof(ZInput), "GetJoyLeftStickY", new[] { typeof(bool) });
|
||||||
|
|
||||||
|
private static float JoyLeftStickY()
|
||||||
|
{
|
||||||
|
if (JoyLeftStickYMethod == null) return 0f;
|
||||||
|
return (float)JoyLeftStickYMethod.Invoke(null, JoyLeftStickYArgs);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Old signature: pass smooth = true, which was its default.
|
||||||
|
private static readonly object[] JoyLeftStickYArgs =
|
||||||
|
JoyLeftStickYMethod != null && JoyLeftStickYMethod.GetParameters().Length == 1 ? new object[] { true } : null;
|
||||||
|
|
||||||
|
public static void Prefix(Character __instance, float dt)
|
||||||
|
{
|
||||||
|
if (__instance != Player.m_localPlayer) return;
|
||||||
|
|
||||||
|
IDirectedFlyer form = DirectedFlight.Flying;
|
||||||
|
if (form == null)
|
||||||
|
{
|
||||||
|
Reversing = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var traverse = Traverse.Create(__instance);
|
||||||
|
Vector3 lookDir = Player.m_localPlayer.GetLookDir();
|
||||||
|
bool input = RaceInput.Allowed;
|
||||||
|
// The pad's half of W/S: the left stick, read with vanilla's own sign -
|
||||||
|
// PlayerController.FixedUpdate takes forward as the NEGATED GetJoyLeftStickY.
|
||||||
|
// Flight only knows powered forward, reverse or neither, so the stick is a
|
||||||
|
// threshold, not a throttle. Steering stays on the camera, i.e. the right stick.
|
||||||
|
float stick = -JoyLeftStickY();
|
||||||
|
// The keyboard side reads vanilla's own Forward/Backward/Run actions, so a key the
|
||||||
|
// player rebound in the settings flies too, not just W, S and Shift.
|
||||||
|
bool forward = input && (ZInput.GetButton("Forward") || stick > StickThreshold);
|
||||||
|
// Forward wins a W+S mash rather than the two cancelling into a dead hover.
|
||||||
|
bool backward = input && !forward && (ZInput.GetButton("Backward") || stick < -StickThreshold);
|
||||||
|
// Sprint on a pad is vanilla's run button, wherever the chosen layout puts it.
|
||||||
|
bool sprintKey = input && (ZInput.GetButton("Run") || ZInput.GetButton("JoyRun"));
|
||||||
|
bool onGround = __instance.IsOnGround();
|
||||||
|
// IsSwimming is the exact test UpdateMotion uses to hand the frame to UpdateSwimming
|
||||||
|
// instead of UpdateFlying, so it is also the one condition DirectedFlightWaterPatch has
|
||||||
|
// to take back. Its half-second tail past leaving the water is welcome here - it
|
||||||
|
// keeps the climb going just long enough to clear the surface properly.
|
||||||
|
bool inWater = __instance.IsSwimming();
|
||||||
|
|
||||||
|
// Powered flight is paid for up front, per frame. A form that cannot pay - out of
|
||||||
|
// stamina, or barred from powering at all - falls through to the glide below rather
|
||||||
|
// than out of the sky.
|
||||||
|
if ((forward || backward) && !(form.CanPower && TrySpendStamina(form.PoweredStaminaPerSecond, dt)))
|
||||||
|
{
|
||||||
|
forward = false;
|
||||||
|
backward = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Reversing = backward;
|
||||||
|
|
||||||
|
// m_run only picks between the two fly speeds. Every mode now has its own speed, so
|
||||||
|
// leave it off and drive all of them through m_flySlowSpeed.
|
||||||
|
traverse.Field("m_run").SetValue(false);
|
||||||
|
|
||||||
|
// UpdateFlying rotates the body toward m_moveDir on its own, but at m_flyTurnSpeed,
|
||||||
|
// which sits at Character's 12 deg/s default because the Player prefab was never set
|
||||||
|
// up as a flying creature - a 90 degree turn would take over seven seconds, so the
|
||||||
|
// model reads as not turning at all. Give it a speed that suits a flying form.
|
||||||
|
traverse.Field("m_flyTurnSpeed").SetValue(form.TurnSpeed);
|
||||||
|
|
||||||
|
// Powered flight, ground contact and clawing out of water all refresh the hover
|
||||||
|
// window, so none of them can be followed by an immediate sink.
|
||||||
|
if (forward || backward || onGround || inWater) form.LastPoweredTime = Time.time;
|
||||||
|
|
||||||
|
Vector3 moveDir = lookDir;
|
||||||
|
float speed;
|
||||||
|
|
||||||
|
if (inWater)
|
||||||
|
{
|
||||||
|
// Wet wings still beat. Water used to be a trap: UpdateMotion hands a swimming
|
||||||
|
// character to UpdateSwimming before it ever looks at m_flying, so a form that
|
||||||
|
// touched the sea was stuck paddling with the flight controls doing nothing.
|
||||||
|
// DirectedFlightWaterPatch gives the frame back to flight, and this branch spends
|
||||||
|
// it climbing regardless of where the camera points, so the surface is always
|
||||||
|
// something you break out of rather than something you sit in. Free on purpose:
|
||||||
|
// a form that could not pay to leave the water would drown in it.
|
||||||
|
moveDir = (Vector3.up + FlatHeading(__instance, lookDir) * LIFTOFF_HEADING_BLEND).normalized;
|
||||||
|
speed = form.LiftoffSpeed;
|
||||||
|
}
|
||||||
|
else if (backward)
|
||||||
|
{
|
||||||
|
// Straight reverse thrust along the aim, pitch included: look down and beat back
|
||||||
|
// and you rise away from what you are looking at, which is the whole point of
|
||||||
|
// having a reverse - you can retreat without taking your eyes (or your breath
|
||||||
|
// attack, which fires along the same vector) off the target.
|
||||||
|
moveDir = -lookDir;
|
||||||
|
speed = form.ReverseSpeed;
|
||||||
|
}
|
||||||
|
else if (forward)
|
||||||
|
{
|
||||||
|
speed = form.BoostSpeed;
|
||||||
|
if (sprintKey && TrySpendStamina(form.SprintStaminaPerSecond, dt)) speed = form.SprintSpeed;
|
||||||
|
}
|
||||||
|
else if (onGround || Time.time - form.LastPoweredTime < form.HoverSeconds)
|
||||||
|
{
|
||||||
|
// Holding station: on the ground this keeps a touchdown from sliding the player
|
||||||
|
// forward forever, and in the air it gives the beats of level flight before the
|
||||||
|
// form starts to sink. m_moveDir stays full length so the body still turns to
|
||||||
|
// face the camera, and zeroing the speed (rather than the rigidbody velocity)
|
||||||
|
// avoids fighting the AddForce UpdateFlying queues, which caused visible jitter.
|
||||||
|
speed = 0f;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Unpowered flight is a glide, not a hover with a joystick: drift along the
|
||||||
|
// heading the camera faces while losing height, so aiming at the sky without
|
||||||
|
// holding W no longer climbs.
|
||||||
|
moveDir = (FlatHeading(__instance, lookDir) + Vector3.down * DESCENT_SLOPE).normalized;
|
||||||
|
speed = form.GlideSpeed;
|
||||||
|
}
|
||||||
|
|
||||||
|
traverse.Field("m_moveDir").SetValue(moveDir);
|
||||||
|
traverse.Field("m_flySlowSpeed").SetValue(speed);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>Aim flattened onto the ground plane, falling back to the body's own facing
|
||||||
|
/// when the player is looking straight up or down.</summary>
|
||||||
|
private static Vector3 FlatHeading(Character character, Vector3 lookDir)
|
||||||
|
{
|
||||||
|
Vector3 heading = new Vector3(lookDir.x, 0f, lookDir.z);
|
||||||
|
if (heading.sqrMagnitude < 0.0001f)
|
||||||
|
{
|
||||||
|
heading = character.transform.forward;
|
||||||
|
heading.y = 0f;
|
||||||
|
}
|
||||||
|
return heading.normalized;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Charges this frame of a per-second cost. Returns false when the player cannot pay.
|
||||||
|
/// A rate of zero is always paid, so a free mode costs nothing and never fails.
|
||||||
|
/// </summary>
|
||||||
|
private static bool TrySpendStamina(float perSecond, float dt)
|
||||||
|
{
|
||||||
|
if (perSecond <= 0f) return true;
|
||||||
|
|
||||||
|
Player player = Player.m_localPlayer;
|
||||||
|
if (player == null) return false;
|
||||||
|
|
||||||
|
float cost = perSecond * dt;
|
||||||
|
if (!player.HaveStamina(cost)) return false;
|
||||||
|
|
||||||
|
player.UseStamina(cost);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Character.UpdateMotion asks IsSwimming before it asks m_flying, so a flying form that
|
||||||
|
/// touched water was handed to UpdateSwimming every frame: the flight patch above never ran,
|
||||||
|
/// the form paddled on the surface, and there was no way back into the air short of finding
|
||||||
|
/// land. Hand those frames back to UpdateFlying, which is the only motion path the two methods
|
||||||
|
/// contend over: nothing else calls either of them, and everything that merely asks
|
||||||
|
/// IsSwimming - the Wet status, the animator, stamina - is left alone.
|
||||||
|
/// </summary>
|
||||||
|
[HarmonyPatch(typeof(Character), "UpdateSwimming")]
|
||||||
|
public static class DirectedFlightWaterPatch
|
||||||
|
{
|
||||||
|
private static readonly MethodInfo UpdateFlyingMethod = AccessTools.Method(typeof(Character), "UpdateFlying");
|
||||||
|
|
||||||
|
public static bool Prefix(Character __instance, float dt)
|
||||||
|
{
|
||||||
|
if (__instance != Player.m_localPlayer) return true;
|
||||||
|
if (DirectedFlight.Flying == null) return true;
|
||||||
|
|
||||||
|
// Fail open: if a game update ever renames the method, swim normally rather than
|
||||||
|
// freezing the player in place with no motion update at all.
|
||||||
|
if (UpdateFlyingMethod == null) return true;
|
||||||
|
|
||||||
|
UpdateFlyingMethod.Invoke(__instance, new object[] { dt });
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -24,11 +24,16 @@ namespace RacesOfValheim
|
||||||
{ "HareMeat", "CookedHareMeat" },
|
{ "HareMeat", "CookedHareMeat" },
|
||||||
{ "ChickenMeat", "CookedChickenMeat" },
|
{ "ChickenMeat", "CookedChickenMeat" },
|
||||||
{ "BugMeat", "CookedBugMeat" },
|
{ "BugMeat", "CookedBugMeat" },
|
||||||
{ "VoltureMeat", "RoastedVoltureMeat" },
|
{ "VoltureMeat", "CookedVoltureMeat" },
|
||||||
{ "GreydwarfEye", "DeerStew" },
|
{ "GreydwarfEye", "DeerStew" },
|
||||||
{ "Entrails", "Sausages" },
|
{ "Entrails", "Sausages" },
|
||||||
{ "Bloodbag", "BloodPudding" },
|
{ "Bloodbag", "BloodPudding" },
|
||||||
{ "MooseMeat", "CookedMooseMeat" },
|
{ "MooseMeat", "CookedMooseMeat" },
|
||||||
|
// Bjorn, the Valheim 1.0 bear.
|
||||||
|
{ "BjornMeat", "CookedBjornMeat" },
|
||||||
|
// Ashlands.
|
||||||
|
{ "AsksvinMeat", "CookedAsksvinMeat" },
|
||||||
|
{ "BoneMawSerpentMeat", "CookedBoneMawSerpentMeat" },
|
||||||
// Raw blubber keeps its own name and icon (EdibleUncooked_ copies them from the raw
|
// Raw blubber keeps its own name and icon (EdibleUncooked_ copies them from the raw
|
||||||
// item) and gives the stats of Seal Meat Soup.
|
// item) and gives the stats of Seal Meat Soup.
|
||||||
{ "SealBlubber", "SealSoup" }
|
{ "SealBlubber", "SealSoup" }
|
||||||
|
|
|
||||||
|
|
@ -76,6 +76,12 @@ namespace RacesOfValheim
|
||||||
private const float PileHeight = 1.05f;
|
private const float PileHeight = 1.05f;
|
||||||
private const float PileSize = 0.45f;
|
private const float PileSize = 0.45f;
|
||||||
|
|
||||||
|
// The dressing, in the same unscaled table space as the pile. The pile owns the centre, so the
|
||||||
|
// tankard stands just clear of it, on the near side.
|
||||||
|
private static readonly Color BankWoodTint = new Color(0.62f, 0.55f, 0.5f, 1f);
|
||||||
|
private static readonly Vector3 TankardSpot = new Vector3(0.45f, PileHeight, -0.25f);
|
||||||
|
private const float TankardSize = 0.38f;
|
||||||
|
|
||||||
public class Troop
|
public class Troop
|
||||||
{
|
{
|
||||||
public string Id;
|
public string Id;
|
||||||
|
|
@ -276,6 +282,12 @@ namespace RacesOfValheim
|
||||||
|
|
||||||
prefab.transform.localScale = Vector3.one * TableScale;
|
prefab.transform.localScale = Vector3.one * TableScale;
|
||||||
|
|
||||||
|
// A counting table, not a map table: darker wood and a dvergr tankard beside the coin.
|
||||||
|
// Tinted BEFORE the tankard goes on, or it would be darkened too.
|
||||||
|
PieceLook.Tint(prefab.transform, BankWoodTint);
|
||||||
|
ModelBorrow.Attach(prefab.transform, "BankTankard", "Tankard_dvergr",
|
||||||
|
TankardSpot, Quaternion.identity, TankardSize, "Dvergar", activeOnly: true);
|
||||||
|
|
||||||
DvergarBancoBehaviour bank = prefab.AddComponent<DvergarBancoBehaviour>();
|
DvergarBancoBehaviour bank = prefab.AddComponent<DvergarBancoBehaviour>();
|
||||||
|
|
||||||
foreach (Switch existing in prefab.GetComponentsInChildren<Switch>(true))
|
foreach (Switch existing in prefab.GetComponentsInChildren<Switch>(true))
|
||||||
|
|
|
||||||
275
JotunnModStub/Dvergar/DvergarCheapBuilding.cs
Normal file
|
|
@ -0,0 +1,275 @@
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using HarmonyLib;
|
||||||
|
using UnityEngine;
|
||||||
|
using UnityEngine.UI;
|
||||||
|
|
||||||
|
namespace RacesOfValheim
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// A Dvergar builds the black marble and Yggdrasil wood building pieces with stone and fine
|
||||||
|
/// wood (Wargles' suggestion). Only structural pieces: stations, furniture, containers and
|
||||||
|
/// fires keep their cost, so nothing with a progression role gets cheaper.
|
||||||
|
///
|
||||||
|
/// The swap is done on the piece prefabs of the Dvergar's own client. The build menu, the
|
||||||
|
/// "known piece" check and ConsumeResources all read the prefab's m_resources, so the menu
|
||||||
|
/// lists the pieces once stone or fine wood is known, and the player pays the swapped cost.
|
||||||
|
///
|
||||||
|
/// The refund is the catch. Piece.DropResources gives back whatever m_resources says on the
|
||||||
|
/// machine that destroys the piece; vanilla never records what was paid. Without help a human
|
||||||
|
/// deconstructing a Dvergar's stone wall would get black marble, and a Dvergar deconstructing a
|
||||||
|
/// vanilla wall would get stone. So a cheap piece is tagged on its ZDO when placed, with the
|
||||||
|
/// ratios it was paid at, and DropResources is given the matching cost on every client.
|
||||||
|
/// </summary>
|
||||||
|
public static class DvergarCheapBuilding
|
||||||
|
{
|
||||||
|
// The ratios a cheap piece was paid at. Absent (0) on every piece placed at full cost.
|
||||||
|
public const string StoneRatioZdoKey = "RacesOfValheim_DvergarCheapStone";
|
||||||
|
public const string WoodRatioZdoKey = "RacesOfValheim_DvergarCheapWood";
|
||||||
|
|
||||||
|
private const string BlackMarble = "BlackMarble";
|
||||||
|
private const string YggdrasilWood = "YggdrasilWood";
|
||||||
|
private const string Stone = "Stone";
|
||||||
|
private const string FineWood = "FineWood";
|
||||||
|
|
||||||
|
private const string LabelName = "rov_dvergar_cheap";
|
||||||
|
|
||||||
|
private const Piece.UsageTagFlags StructuralTags =
|
||||||
|
Piece.UsageTagFlags.Building | Piece.UsageTagFlags.Floor | Piece.UsageTagFlags.Wall |
|
||||||
|
Piece.UsageTagFlags.Roof | Piece.UsageTagFlags.Architecture | Piece.UsageTagFlags.Stairs |
|
||||||
|
Piece.UsageTagFlags.Doors;
|
||||||
|
|
||||||
|
// Piece prefab name -> its vanilla cost. Collected once and kept: the prefabs live for the
|
||||||
|
// whole session, and the originals must survive every swap.
|
||||||
|
private static Dictionary<string, Piece.Requirement[]> originals;
|
||||||
|
private static Dictionary<string, Piece> prefabs;
|
||||||
|
private static ItemDrop stoneItem, fineWoodItem;
|
||||||
|
|
||||||
|
// "" while the prefabs carry their vanilla cost, otherwise the ratios they were swapped at.
|
||||||
|
private static string appliedKey = "";
|
||||||
|
|
||||||
|
private static bool Collect()
|
||||||
|
{
|
||||||
|
if (originals != null) return true;
|
||||||
|
if (ObjectDB.instance == null) return false;
|
||||||
|
|
||||||
|
GameObject hammer = ObjectDB.instance.GetItemPrefab("Hammer");
|
||||||
|
PieceTable table = hammer != null ? hammer.GetComponent<ItemDrop>()?.m_itemData?.m_shared?.m_buildPieces : null;
|
||||||
|
stoneItem = ObjectDB.instance.GetItemPrefab(Stone)?.GetComponent<ItemDrop>();
|
||||||
|
fineWoodItem = ObjectDB.instance.GetItemPrefab(FineWood)?.GetComponent<ItemDrop>();
|
||||||
|
if (table == null || stoneItem == null || fineWoodItem == null) return false;
|
||||||
|
|
||||||
|
originals = new Dictionary<string, Piece.Requirement[]>();
|
||||||
|
prefabs = new Dictionary<string, Piece>();
|
||||||
|
foreach (GameObject go in table.m_pieces)
|
||||||
|
{
|
||||||
|
Piece piece = go != null ? go.GetComponent<Piece>() : null;
|
||||||
|
if (piece == null || piece.m_resources == null || !UsesSwappedMaterial(piece) || !IsBuildingPiece(piece)) continue;
|
||||||
|
|
||||||
|
originals[go.name] = piece.m_resources;
|
||||||
|
prefabs[go.name] = piece;
|
||||||
|
// The list to read once in game: every piece that changes cost, and where it is built.
|
||||||
|
Jotunn.Logger.LogInfo($"[Dvergar] Cheap building: {go.name} at {(piece.m_craftingStation != null ? piece.m_craftingStation.name : "no station")}, {Describe(piece.m_resources)} -> {Describe(BuildCheap(piece.m_resources, 3, 2))} (at 3/2)");
|
||||||
|
}
|
||||||
|
Jotunn.Logger.LogInfo($"[Dvergar] Cheap building: {originals.Count} pieces.");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static bool UsesSwappedMaterial(Piece piece)
|
||||||
|
{
|
||||||
|
foreach (Piece.Requirement req in piece.m_resources)
|
||||||
|
{
|
||||||
|
if (req.m_resItem == null) continue;
|
||||||
|
string name = req.m_resItem.name;
|
||||||
|
if (name == BlackMarble || name == YggdrasilWood) return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static bool IsBuildingPiece(Piece piece)
|
||||||
|
{
|
||||||
|
bool structural = piece.m_category == Piece.PieceCategory.BuildingWorkbench
|
||||||
|
|| piece.m_category == Piece.PieceCategory.BuildingStonecutter
|
||||||
|
|| (piece.m_usage & StructuralTags) != 0;
|
||||||
|
if (!structural) return false;
|
||||||
|
if ((piece.m_usage & Piece.UsageTagFlags.Crafting) != 0) return false;
|
||||||
|
|
||||||
|
// Anything that does a job keeps its cost, whatever its tags say.
|
||||||
|
return piece.GetComponentInChildren<CraftingStation>() == null
|
||||||
|
&& piece.GetComponentInChildren<StationExtension>() == null
|
||||||
|
&& piece.GetComponentInChildren<Container>() == null
|
||||||
|
&& piece.GetComponentInChildren<Fireplace>() == null
|
||||||
|
&& piece.GetComponentInChildren<Smelter>() == null
|
||||||
|
&& piece.m_comfort <= 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The cost with black marble and Yggdrasil wood swapped out. New Requirement objects
|
||||||
|
/// throughout: the originals are shared with the prefab and must stay untouched. A
|
||||||
|
/// material the piece already had (some marble pieces also ask for stone) is merged.
|
||||||
|
/// </summary>
|
||||||
|
private static Piece.Requirement[] BuildCheap(Piece.Requirement[] original, int stoneRatio, int woodRatio)
|
||||||
|
{
|
||||||
|
var result = new List<Piece.Requirement>();
|
||||||
|
foreach (Piece.Requirement req in original)
|
||||||
|
{
|
||||||
|
ItemDrop item = req.m_resItem;
|
||||||
|
int amount = req.m_amount;
|
||||||
|
if (item != null && item.name == BlackMarble) { item = stoneItem; amount *= stoneRatio; }
|
||||||
|
else if (item != null && item.name == YggdrasilWood) { item = fineWoodItem; amount *= woodRatio; }
|
||||||
|
|
||||||
|
Piece.Requirement same = item != null ? result.Find(r => r.m_resItem == item) : null;
|
||||||
|
if (same != null)
|
||||||
|
{
|
||||||
|
same.m_amount += amount;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
result.Add(new Piece.Requirement
|
||||||
|
{
|
||||||
|
m_resItem = item,
|
||||||
|
m_amount = amount,
|
||||||
|
m_extraAmountOnlyOneIngredient = req.m_extraAmountOnlyOneIngredient,
|
||||||
|
m_amountPerLevel = req.m_amountPerLevel,
|
||||||
|
m_upgraderResource = req.m_upgraderResource,
|
||||||
|
m_recover = req.m_recover,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return result.ToArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static string Describe(Piece.Requirement[] reqs)
|
||||||
|
{
|
||||||
|
var parts = new List<string>();
|
||||||
|
foreach (Piece.Requirement req in reqs)
|
||||||
|
{
|
||||||
|
if (req.m_resItem != null) parts.Add($"{req.m_amount} {req.m_resItem.name}");
|
||||||
|
}
|
||||||
|
return string.Join(", ", parts);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Puts the cost the local player should see on the prefabs. Returns whether anything
|
||||||
|
/// changed, so the caller knows to refresh the build menu.
|
||||||
|
/// </summary>
|
||||||
|
private static bool Apply(bool cheap)
|
||||||
|
{
|
||||||
|
int stone = DvergarConfigManagement.CheapStonePerBlackMarble.Value;
|
||||||
|
int wood = DvergarConfigManagement.CheapFineWoodPerYggdrasil.Value;
|
||||||
|
string key = cheap ? stone + "/" + wood : "";
|
||||||
|
if (key == appliedKey) return false;
|
||||||
|
|
||||||
|
foreach (var pair in originals)
|
||||||
|
{
|
||||||
|
if (!prefabs.TryGetValue(pair.Key, out Piece prefab) || prefab == null) continue;
|
||||||
|
prefab.m_resources = cheap ? BuildCheap(pair.Value, stone, wood) : pair.Value;
|
||||||
|
}
|
||||||
|
appliedKey = key;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static bool IsSwapped(Piece piece)
|
||||||
|
{
|
||||||
|
return appliedKey != "" && piece != null && originals != null
|
||||||
|
&& originals.ContainsKey(Utils.GetPrefabName(piece.gameObject.name));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Keeps the prefabs in step with the local player: a Dvergar with the option on sees the
|
||||||
|
/// cheap cost, anyone else the vanilla one. Checked every frame because the race can change
|
||||||
|
/// mid-session (resetrace) and the ratios with the server's config; the check is a string
|
||||||
|
/// compare unless something changed.
|
||||||
|
/// </summary>
|
||||||
|
[HarmonyPatch(typeof(Player), "Update")]
|
||||||
|
public static class Dvergar_CheapBuildingSync_Patch
|
||||||
|
{
|
||||||
|
public static void Postfix(Player __instance)
|
||||||
|
{
|
||||||
|
if (__instance != Player.m_localPlayer || !Collect()) return;
|
||||||
|
|
||||||
|
bool cheap = DvergarConfigManagement.CheapBuildingEnabled.Value && DvergarRace.IsDvergar();
|
||||||
|
if (Apply(cheap)) Traverse.Create(__instance).Method("UpdateAvailablePiecesList").GetValue();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Tags a piece placed at the cheap cost. SetCreator is called once, by PlacePiece, on the
|
||||||
|
/// placing client, right after the piece was paid for from the same prefab cost.
|
||||||
|
/// </summary>
|
||||||
|
[HarmonyPatch(typeof(Piece), nameof(Piece.SetCreator))]
|
||||||
|
public static class Dvergar_CheapBuildingTag_Patch
|
||||||
|
{
|
||||||
|
public static void Postfix(Piece __instance)
|
||||||
|
{
|
||||||
|
if (!IsSwapped(__instance)) return;
|
||||||
|
|
||||||
|
ZNetView nview = __instance.GetComponent<ZNetView>();
|
||||||
|
if (nview == null || !nview.IsValid() || !nview.IsOwner()) return;
|
||||||
|
|
||||||
|
nview.GetZDO().Set(StoneRatioZdoKey, DvergarConfigManagement.CheapStonePerBlackMarble.Value);
|
||||||
|
nview.GetZDO().Set(WoodRatioZdoKey, DvergarConfigManagement.CheapFineWoodPerYggdrasil.Value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gives back what the piece cost: the cheap materials at the ratios it was paid at for a
|
||||||
|
/// tagged piece, the vanilla cost for every other one, whoever destroys it and whatever
|
||||||
|
/// cost this client's prefab carries right now.
|
||||||
|
/// </summary>
|
||||||
|
[HarmonyPatch(typeof(Piece), nameof(Piece.DropResources))]
|
||||||
|
public static class Dvergar_CheapBuildingRefund_Patch
|
||||||
|
{
|
||||||
|
public static void Prefix(Piece __instance)
|
||||||
|
{
|
||||||
|
if (!Collect()) return;
|
||||||
|
if (!originals.TryGetValue(Utils.GetPrefabName(__instance.gameObject.name), out Piece.Requirement[] original)) return;
|
||||||
|
|
||||||
|
ZNetView nview = __instance.GetComponent<ZNetView>();
|
||||||
|
ZDO zdo = nview != null && nview.IsValid() ? nview.GetZDO() : null;
|
||||||
|
int stone = zdo != null ? zdo.GetInt(StoneRatioZdoKey, 0) : 0;
|
||||||
|
int wood = zdo != null ? zdo.GetInt(WoodRatioZdoKey, 0) : 0;
|
||||||
|
|
||||||
|
__instance.m_resources = stone > 0 && wood > 0 ? BuildCheap(original, stone, wood) : original;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The Dvergar icon on every swapped piece in the hammer menu. Valheim 1.0
|
||||||
|
/// draws that menu with BuildUi, one pooled BuildUiPieceButton per piece, and Setup is
|
||||||
|
/// where a button takes its piece. The old Hud.UpdatePieceList grid still runs but is
|
||||||
|
/// hidden, so a label there is never seen.
|
||||||
|
/// </summary>
|
||||||
|
[HarmonyPatch(typeof(BuildUiPieceButton), nameof(BuildUiPieceButton.Setup))]
|
||||||
|
public static class Dvergar_CheapBuildingLabel_Patch
|
||||||
|
{
|
||||||
|
public static void Postfix(BuildUiPieceButton __instance, Piece pieceInfo)
|
||||||
|
{
|
||||||
|
bool cheap = IsSwapped(pieceInfo);
|
||||||
|
Transform label = __instance.transform.Find(LabelName);
|
||||||
|
if (label == null)
|
||||||
|
{
|
||||||
|
if (!cheap) return;
|
||||||
|
label = CreateLabel(__instance.transform);
|
||||||
|
}
|
||||||
|
if (label.gameObject.activeSelf != cheap) label.gameObject.SetActive(cheap);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Transform CreateLabel(Transform button)
|
||||||
|
{
|
||||||
|
var obj = new GameObject(LabelName, typeof(RectTransform));
|
||||||
|
obj.transform.SetParent(button, false);
|
||||||
|
|
||||||
|
// The race's own icon in the bottom-right corner, as the race menu and the build
|
||||||
|
// panel's race requirement show it: no text, so it fits in every language.
|
||||||
|
var rect = (RectTransform)obj.transform;
|
||||||
|
rect.anchorMin = rect.anchorMax = rect.pivot = new Vector2(1f, 0f);
|
||||||
|
rect.anchoredPosition = new Vector2(-2f, 2f);
|
||||||
|
rect.sizeDelta = new Vector2(22f, 22f);
|
||||||
|
|
||||||
|
var image = obj.AddComponent<Image>();
|
||||||
|
image.sprite = RacesOfValheim.RaceIcon(DvergarConfig.RaceId);
|
||||||
|
image.preserveAspect = true;
|
||||||
|
image.raycastTarget = false;
|
||||||
|
return obj.transform;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -124,9 +124,11 @@ namespace RacesOfValheim
|
||||||
// still clearing by about 2mm. Same size of eye, sitting deeper, and the cap is flatter
|
// still clearing by about 2mm. Same size of eye, sitting deeper, and the cap is flatter
|
||||||
// for it - which is what reads as set into the skull rather than resting on it.
|
// for it - which is what reads as set into the skull rather than resting on it.
|
||||||
public static readonly float EyeSeparation = 0.032f; // half the distance between them
|
public static readonly float EyeSeparation = 0.032f; // half the distance between them
|
||||||
public static readonly float EyeForward = 0.081f; // centre ~63mm out
|
public static readonly float EyeForward = 0.085f; // 0.081 left the smaller ball buried
|
||||||
public static readonly float EyeHeight = 0.181f; // ~15mm lower than before
|
public static readonly float EyeHeight = 0.181f; // ~15mm lower than before
|
||||||
public static readonly float EyeSize = 0.062f; // ~48mm across, so a 24mm radius
|
// Then cut down after playtest: at 0.062 the cap read as two lamps covering the face. An
|
||||||
|
// 18mm radius at the same depth leaves a cap of about 22mm on a 0.78 Dvergar.
|
||||||
|
public static readonly float EyeSize = 0.036f;
|
||||||
|
|
||||||
// How hard the eyes burn. The colours the game gives a starred dverger are HDR - one star
|
// How hard the eyes burn. The colours the game gives a starred dverger are HDR - one star
|
||||||
// is (0, 4, 3.3) - and anything past 1 clips to white on the way to the bloom pass, which
|
// is (0, 4, 3.3) - and anything past 1 clips to white on the way to the bloom pass, which
|
||||||
|
|
|
||||||
|
|
@ -57,6 +57,11 @@ namespace RacesOfValheim
|
||||||
public static ConfigEntry<float> RunicOverchargeWindow;
|
public static ConfigEntry<float> RunicOverchargeWindow;
|
||||||
public static ConfigEntry<float> RunicOverchargeCooldown;
|
public static ConfigEntry<float> RunicOverchargeCooldown;
|
||||||
|
|
||||||
|
// ─── Cheap Building ───────────────────────────────────────────────────────
|
||||||
|
public static ConfigEntry<bool> CheapBuildingEnabled;
|
||||||
|
public static ConfigEntry<int> CheapStonePerBlackMarble;
|
||||||
|
public static ConfigEntry<int> CheapFineWoodPerYggdrasil;
|
||||||
|
|
||||||
public static void Bind(ConfigFile config)
|
public static void Bind(ConfigFile config)
|
||||||
{
|
{
|
||||||
const string keybinds = "Dvergar - Keybinds";
|
const string keybinds = "Dvergar - Keybinds";
|
||||||
|
|
@ -106,6 +111,14 @@ namespace RacesOfValheim
|
||||||
new ConfigDescription("Seconds a loaded charge is held before it lapses unused.", new AcceptableValueRange<float>(1f, 60f)));
|
new ConfigDescription("Seconds a loaded charge is held before it lapses unused.", new AcceptableValueRange<float>(1f, 60f)));
|
||||||
RunicOverchargeCooldown = config.Bind(overcharge, "Cooldown", 60f,
|
RunicOverchargeCooldown = config.Bind(overcharge, "Cooldown", 60f,
|
||||||
new ConfigDescription("Seconds between casts.", new AcceptableValueRange<float>(0f, 300f)));
|
new ConfigDescription("Seconds between casts.", new AcceptableValueRange<float>(0f, 300f)));
|
||||||
|
|
||||||
|
const string building = "Dvergar - Cheap Building";
|
||||||
|
CheapBuildingEnabled = config.Bind(building, "Enabled", true,
|
||||||
|
new ConfigDescription("A Dvergar builds the black marble and Yggdrasil wood building pieces (walls, floors, beams, roofs, arches, stairs) with stone and fine wood instead. Stations and furniture keep their cost. A deconstructed piece gives back what was paid for it."));
|
||||||
|
CheapStonePerBlackMarble = config.Bind(building, "Stone per Black Marble", 3,
|
||||||
|
new ConfigDescription("Stone a Dvergar pays for each black marble in a piece's cost.", new AcceptableValueRange<int>(1, 10)));
|
||||||
|
CheapFineWoodPerYggdrasil = config.Bind(building, "Fine Wood per Yggdrasil Wood", 2,
|
||||||
|
new ConfigDescription("Fine wood a Dvergar pays for each Yggdrasil wood in a piece's cost.", new AcceptableValueRange<int>(1, 10)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -277,10 +277,11 @@ namespace RacesOfValheim
|
||||||
// metre was the entire drift: the offsets below are under a centimetre in local units
|
// metre was the entire drift: the offsets below are under a centimetre in local units
|
||||||
// and never stood a chance of mattering next to it.
|
// and never stood a chance of mattering next to it.
|
||||||
float raceScale = GetVisualScale(player);
|
float raceScale = GetVisualScale(player);
|
||||||
Vector3 baseLocal = localForward * (DvergarConfig.EyeForward * raceScale * toLocal)
|
|
||||||
+ localUp * (DvergarConfig.EyeHeight * raceScale * toLocal);
|
|
||||||
|
|
||||||
float eyeLocalSize = DvergarConfig.EyeSize * raceScale * toLocal;
|
float height = DvergarConfig.EyeHeight;
|
||||||
|
float separation = DvergarConfig.EyeSeparation;
|
||||||
|
float eyeSize = DvergarConfig.EyeSize;
|
||||||
|
PlayerFace.AdjustEyes(player, ref height, ref separation, ref eyeSize);
|
||||||
|
|
||||||
for (int i = 0; i < holder.childCount; i++)
|
for (int i = 0; i < holder.childCount; i++)
|
||||||
{
|
{
|
||||||
|
|
@ -291,9 +292,25 @@ namespace RacesOfValheim
|
||||||
// curved and the two sides do not present the same surface to a ball of this
|
// curved and the two sides do not present the same surface to a ball of this
|
||||||
// radius.
|
// radius.
|
||||||
float side = i == 0 ? -1f : 1f;
|
float side = i == 0 ? -1f : 1f;
|
||||||
float size = i == 0 ? eyeLocalSize * DvergarConfig.LeftEyeSizeMultiplier : eyeLocalSize;
|
|
||||||
|
|
||||||
eye.localPosition = baseLocal + localRight * (side * DvergarConfig.EyeSeparation * raceScale * toLocal);
|
// This eye's hand corrections (RaceEyeTuning).
|
||||||
|
float forward = DvergarConfig.EyeForward;
|
||||||
|
float eyeHeight = height;
|
||||||
|
float eyeSeparation = separation;
|
||||||
|
float size = eyeSize * raceScale * toLocal;
|
||||||
|
RaceEyeTuning.Eye tuning = RaceEyeTuning.For(DvergarConfig.RaceId, player, side);
|
||||||
|
if (tuning != null)
|
||||||
|
{
|
||||||
|
forward += tuning.Forward;
|
||||||
|
eyeHeight += tuning.Height;
|
||||||
|
eyeSeparation += tuning.Separation;
|
||||||
|
size *= tuning.Size;
|
||||||
|
}
|
||||||
|
if (i == 0) size *= DvergarConfig.LeftEyeSizeMultiplier;
|
||||||
|
|
||||||
|
eye.localPosition = localForward * (forward * raceScale * toLocal)
|
||||||
|
+ localUp * (eyeHeight * raceScale * toLocal)
|
||||||
|
+ localRight * (side * eyeSeparation * raceScale * toLocal);
|
||||||
eye.localScale = Vector3.one * size;
|
eye.localScale = Vector3.one * size;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -54,9 +54,17 @@ namespace RacesOfValheim
|
||||||
//
|
//
|
||||||
// Skeleton_Hildir stays out deliberately, on the same rule that keeps GoblinKing and the
|
// Skeleton_Hildir stays out deliberately, on the same rule that keeps GoblinKing and the
|
||||||
// Hildir brothers out of the Black Forest set: a quest boss is not somebody's kin.
|
// Hildir brothers out of the Black Forest set: a quest boss is not somebody's kin.
|
||||||
|
//
|
||||||
|
// Valheim 1.0 added a skeleton per region (the green swamp ones and the blue mountain ones
|
||||||
|
// players noticed first), each with a melee-only twin, and spawners place those instead
|
||||||
|
// of the plain Skeleton. Left out, they fought a Skeleton player the plain ones ignored.
|
||||||
private static readonly HashSet<string> PaludeMobs = new HashSet<string>
|
private static readonly HashSet<string> PaludeMobs = new HashSet<string>
|
||||||
{
|
{
|
||||||
"Ghost", "Skeleton", "Skeleton_NoArcher", "Skeleton_Poison", // Skeleton, Rancid remains
|
"Ghost", "Skeleton", "Skeleton_NoArcher", "Skeleton_Poison", // Skeleton, Rancid remains
|
||||||
|
"Skeleton_Meadows", "Skeleton_Meadows_noarcher",
|
||||||
|
"Skeleton_Swamps", "Skeleton_Swamps_noarcher",
|
||||||
|
"Skeleton_Mountains", "Skeleton_Mountains_noarcher",
|
||||||
|
"Skeleton_DeepNorth",
|
||||||
"Draugr", "Draugr_Elite", "Draugr_Ranged",
|
"Draugr", "Draugr_Elite", "Draugr_Ranged",
|
||||||
"Wraith", "Leech", "Abomination",
|
"Wraith", "Leech", "Abomination",
|
||||||
"Blob", "BlobElite", "BlobTar", // Blob, Oozer, Growth
|
"Blob", "BlobElite", "BlobTar", // Blob, Oozer, Growth
|
||||||
|
|
@ -157,6 +165,10 @@ namespace RacesOfValheim
|
||||||
if (!__result) return; // already not enemies, nothing to add
|
if (!__result) return; // already not enemies, nothing to add
|
||||||
if (a == null || b == null) return;
|
if (a == null || b == null) return;
|
||||||
|
|
||||||
|
// The player's own blow. Peace is the creature's choice, not a shield. See
|
||||||
|
// RaceGrudge.StrikeScope.
|
||||||
|
if (RaceGrudge.PlayerStrikes(a)) return;
|
||||||
|
|
||||||
if (IsThrallTruce(a, b) || IsThrallTruce(b, a))
|
if (IsThrallTruce(a, b) || IsThrallTruce(b, a))
|
||||||
{
|
{
|
||||||
__result = false;
|
__result = false;
|
||||||
|
|
|
||||||
|
|
@ -337,7 +337,16 @@ namespace RacesOfValheim
|
||||||
{ "Draugr_Elite", DraugrShop },
|
{ "Draugr_Elite", DraugrShop },
|
||||||
|
|
||||||
{ "Skeleton", SkeletonShop },
|
{ "Skeleton", SkeletonShop },
|
||||||
|
{ "Skeleton_NoArcher", SkeletonShop },
|
||||||
{ "Skeleton_Poison", SkeletonShop },
|
{ "Skeleton_Poison", SkeletonShop },
|
||||||
|
// Valheim 1.0's regional skeletons, the ones its spawners actually place.
|
||||||
|
{ "Skeleton_Meadows", SkeletonShop },
|
||||||
|
{ "Skeleton_Meadows_noarcher", SkeletonShop },
|
||||||
|
{ "Skeleton_Swamps", SkeletonShop },
|
||||||
|
{ "Skeleton_Swamps_noarcher", SkeletonShop },
|
||||||
|
{ "Skeleton_Mountains", SkeletonShop },
|
||||||
|
{ "Skeleton_Mountains_noarcher", SkeletonShop },
|
||||||
|
{ "Skeleton_DeepNorth", SkeletonShop },
|
||||||
|
|
||||||
{ "Ghost", GhostShop },
|
{ "Ghost", GhostShop },
|
||||||
{ "Wraith", WraithShop },
|
{ "Wraith", WraithShop },
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,8 @@ namespace RacesOfValheim
|
||||||
public static ConfigEntry<bool> HostilityEnabled;
|
public static ConfigEntry<bool> HostilityEnabled;
|
||||||
public static ConfigEntry<bool> MerchantsEnabled;
|
public static ConfigEntry<bool> MerchantsEnabled;
|
||||||
public static ConfigEntry<float> GrudgeDuration;
|
public static ConfigEntry<float> GrudgeDuration;
|
||||||
|
public static ConfigEntry<bool> GrudgeSpreadEnabled;
|
||||||
|
public static ConfigEntry<float> GrudgeSpreadRadius;
|
||||||
|
|
||||||
// Null-safe, defaulting to ON, for the same reason WarVultureConfig guards its own reads:
|
// Null-safe, defaulting to ON, for the same reason WarVultureConfig guards its own reads:
|
||||||
// a patch that somehow runs before Bind() should behave like the shipped default rather
|
// a patch that somehow runs before Bind() should behave like the shipped default rather
|
||||||
|
|
@ -28,6 +30,8 @@ namespace RacesOfValheim
|
||||||
public static bool Hostility => HostilityEnabled?.Value ?? true;
|
public static bool Hostility => HostilityEnabled?.Value ?? true;
|
||||||
public static bool Merchants => MerchantsEnabled?.Value ?? true;
|
public static bool Merchants => MerchantsEnabled?.Value ?? true;
|
||||||
public static float GrudgeSeconds => GrudgeDuration?.Value ?? 60f;
|
public static float GrudgeSeconds => GrudgeDuration?.Value ?? 60f;
|
||||||
|
public static bool GrudgeSpreads => GrudgeSpreadEnabled?.Value ?? false;
|
||||||
|
public static float GrudgeSpreadMeters => GrudgeSpreadRadius?.Value ?? 20f;
|
||||||
|
|
||||||
public static void Bind(ConfigFile config)
|
public static void Bind(ConfigFile config)
|
||||||
{
|
{
|
||||||
|
|
@ -55,11 +59,24 @@ namespace RacesOfValheim
|
||||||
"Without this the truce is absolute in both directions: MonsterAI.UpdateTarget " +
|
"Without this the truce is absolute in both directions: MonsterAI.UpdateTarget " +
|
||||||
"throws away any target BaseAI.IsEnemy calls a non-enemy, so a truced mob could " +
|
"throws away any target BaseAI.IsEnemy calls a non-enemy, so a truced mob could " +
|
||||||
"not fight back even after being struck - it stood still, or fled because it " +
|
"not fight back even after being struck - it stood still, or fled because it " +
|
||||||
"was hurt and had no enemy it was allowed to have. The grudge is per attacker " +
|
"was hurt and had no enemy it was allowed to have. Each creature holds one " +
|
||||||
"and per creature, on whichever machine runs that creature's AI. 0 restores the " +
|
"grudge, against the last player who hit it, and keeps it when another player's " +
|
||||||
|
"game takes over running that creature. 0 restores the " +
|
||||||
"old absolute truce.",
|
"old absolute truce.",
|
||||||
new AcceptableValueRange<float>(0f, 600f)));
|
new AcceptableValueRange<float>(0f, 600f)));
|
||||||
|
|
||||||
|
// Joacwoo's request: the truce made the swamp and the crypts a walk for a Skeleton,
|
||||||
|
// since only the one creature you hit ever fought back.
|
||||||
|
GrudgeSpreadEnabled = config.Bind(factions, "Grudge spreads to kin", false,
|
||||||
|
new ConfigDescription("Off: only the creature you hit fights back. On: hit a creature of your " +
|
||||||
|
"own faction and every creature of that faction near it turns on you too, " +
|
||||||
|
"for the same Faction grudge time, the way vanilla's Dvergr treat a human. " +
|
||||||
|
"Peace still holds until you strike first."));
|
||||||
|
GrudgeSpreadRadius = config.Bind(factions, "Grudge spread radius", 20f,
|
||||||
|
new ConfigDescription("Meters around the creature you hit within which its kin join the fight, " +
|
||||||
|
"with Grudge spreads to kin on.",
|
||||||
|
new AcceptableValueRange<float>(5f, 60f)));
|
||||||
|
|
||||||
MerchantsEnabled = config.Bind(factions, "Faction merchants", true,
|
MerchantsEnabled = config.Bind(factions, "Faction merchants", true,
|
||||||
new ConfigDescription("Certain mobs of your own faction can be traded with - 'E - Talk' opens a shop " +
|
new ConfigDescription("Certain mobs of your own faction can be traded with - 'E - Talk' opens a shop " +
|
||||||
"where you sell them what their kind wants. Turn this off and they are ordinary " +
|
"where you sell them what their kind wants. Turn this off and they are ordinary " +
|
||||||
|
|
|
||||||
|
|
@ -323,17 +323,72 @@ namespace RacesOfValheim
|
||||||
GameObject fireVfx = ZNetScene.instance.GetPrefab("fx_fenring_flames");
|
GameObject fireVfx = ZNetScene.instance.GetPrefab("fx_fenring_flames");
|
||||||
if (fireVfx == null) return null;
|
if (fireVfx == null) return null;
|
||||||
|
|
||||||
GameObject instance = Object.Instantiate(fireVfx, player.transform.position + Vector3.up * 1.5f + player.transform.forward, player.transform.rotation, player.transform);
|
GameObject instance = Object.Instantiate(fireVfx, MouthPoint(player), player.transform.rotation, player.transform);
|
||||||
|
instance.AddComponent<CultistFlameFollow>().Player = player;
|
||||||
|
|
||||||
|
// The vanilla effect is one throw, not a held breath: its emitters do not loop (2 s) and
|
||||||
|
// a TimedDestruction removes it after 5 s, so a long hold went on draining eitr with no
|
||||||
|
// fire. It loops here and lives until StopFire takes it down.
|
||||||
|
TimedDestruction timer = instance.GetComponent<TimedDestruction>();
|
||||||
|
if (timer != null)
|
||||||
|
{
|
||||||
|
timer.CancelInvoke();
|
||||||
|
Object.Destroy(timer);
|
||||||
|
}
|
||||||
|
|
||||||
// Aumentiamo la durata delle particelle del 20%
|
// Aumentiamo la durata delle particelle del 20%
|
||||||
foreach (ParticleSystem ps in instance.GetComponentsInChildren<ParticleSystem>())
|
foreach (ParticleSystem ps in instance.GetComponentsInChildren<ParticleSystem>())
|
||||||
{
|
{
|
||||||
var main = ps.main;
|
var main = ps.main;
|
||||||
main.startLifetimeMultiplier *= 1.2f;
|
main.startLifetimeMultiplier *= 1.2f;
|
||||||
|
main.loop = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// The roar of the fire, the same one-throw story: set before its ZSFX first plays.
|
||||||
|
foreach (ZSFX sfx in instance.GetComponentsInChildren<ZSFX>())
|
||||||
|
{
|
||||||
|
sfx.m_fadeOutOnAwake = false;
|
||||||
|
AudioSource source = sfx.GetComponent<AudioSource>();
|
||||||
|
if (source != null) source.loop = true;
|
||||||
}
|
}
|
||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Bone names the breath leaves from, mouth first. Matched by name anywhere under the form.
|
||||||
|
private static readonly string[] MouthBones = { "Jaw", "Head" };
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Where the Cultist's breath starts: just ahead of the form's jaw (or head), so it leaves the
|
||||||
|
/// mouth at whatever size the form stands. It used to be a fixed 1.5 m above the player's
|
||||||
|
/// feet, chest height on a Cultist, which is the "fire starts too low" report. Falls back on
|
||||||
|
/// that fixed point if the form has neither bone.
|
||||||
|
/// </summary>
|
||||||
|
public static Vector3 MouthPoint(Player player) => MouthPoint(player, FindMouth(player));
|
||||||
|
|
||||||
|
public static Vector3 MouthPoint(Player player, Transform bone)
|
||||||
|
{
|
||||||
|
Transform body = player.transform;
|
||||||
|
return bone != null
|
||||||
|
? bone.position + body.forward * 0.3f
|
||||||
|
: body.position + Vector3.up * 1.5f + body.forward;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Transform FindMouth(Player player)
|
||||||
|
{
|
||||||
|
foreach (string wanted in MouthBones)
|
||||||
|
{
|
||||||
|
foreach (Transform child in player.transform)
|
||||||
|
{
|
||||||
|
if (child.name == "Visual" || !child.gameObject.activeInHierarchy) continue;
|
||||||
|
foreach (Transform t in child.GetComponentsInChildren<Transform>())
|
||||||
|
{
|
||||||
|
if (string.Equals(t.name, wanted, System.StringComparison.OrdinalIgnoreCase)) return t;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
public static void PublishFire(bool on)
|
public static void PublishFire(bool on)
|
||||||
{
|
{
|
||||||
Player player = Player.m_localPlayer;
|
Player player = Player.m_localPlayer;
|
||||||
|
|
@ -393,6 +448,8 @@ namespace RacesOfValheim
|
||||||
private ZNetView nview;
|
private ZNetView nview;
|
||||||
private string lastAttack;
|
private string lastAttack;
|
||||||
private GameObject flames;
|
private GameObject flames;
|
||||||
|
private bool breathing;
|
||||||
|
private float breathStarted;
|
||||||
private readonly FormLocomotion locomotion = new FormLocomotion();
|
private readonly FormLocomotion locomotion = new FormLocomotion();
|
||||||
|
|
||||||
// The flames hang off the player, not this model, so they outlive it unless taken down.
|
// The flames hang off the player, not this model, so they outlive it unless taken down.
|
||||||
|
|
@ -433,18 +490,31 @@ namespace RacesOfValheim
|
||||||
|
|
||||||
bool fire = nview.GetZDO().GetBool(FenrirAttackSync.FireKey, false);
|
bool fire = nview.GetZDO().GetBool(FenrirAttackSync.FireKey, false);
|
||||||
|
|
||||||
// The breath itself: up while the flag is, gone when it drops. Only the cultist ever
|
// The flag is up for the whole hold, wind-up included, as on the owner's side; the
|
||||||
// sets the flag, so no other form can grow flames here.
|
// flames come at the same point of the same clip (CultistBreathClip). Only the cultist
|
||||||
if (fire && flames == null)
|
// ever sets the flag, so no other form can grow flames here.
|
||||||
|
if (fire && !breathing)
|
||||||
{
|
{
|
||||||
flames = FenrirAttackSync.SpawnFlames(player);
|
breathing = true;
|
||||||
|
breathStarted = Time.time;
|
||||||
|
|
||||||
// The roar that opens the breath, once per start, the same cue the owner hears.
|
// The roar that opens the breath, once per start, the same cue the owner hears.
|
||||||
// "sfx_cultist_attack_fire_start" was asked for here and there is no sfx_cultist_*
|
// "sfx_cultist_attack_fire_start" was asked for here and there is no sfx_cultist_*
|
||||||
// prefab in the game at all; the fenring's own fire-claw snarl is the real one.
|
// prefab in the game at all; the fenring's own fire-claw snarl is the real one.
|
||||||
FenrirCreatureSound.PlayFireRoar(player.transform.position);
|
FenrirCreatureSound.PlayFireRoar(player.transform.position);
|
||||||
}
|
}
|
||||||
else if (!fire && flames != null) { Destroy(flames); flames = null; }
|
if (fire)
|
||||||
|
{
|
||||||
|
CultistBreathClip.Hold(formAnim);
|
||||||
|
if (flames == null && CultistBreathClip.FlamesDue(formAnim, breathStarted))
|
||||||
|
flames = FenrirAttackSync.SpawnFlames(player);
|
||||||
|
}
|
||||||
|
else if (breathing)
|
||||||
|
{
|
||||||
|
breathing = false;
|
||||||
|
CultistBreathClip.Release(formAnim, player);
|
||||||
|
if (flames != null) { Destroy(flames); flames = null; }
|
||||||
|
}
|
||||||
|
|
||||||
foreach (AnimatorControllerParameter p in formAnim.parameters)
|
foreach (AnimatorControllerParameter p in formAnim.parameters)
|
||||||
{
|
{
|
||||||
|
|
@ -550,15 +620,15 @@ namespace RacesOfValheim
|
||||||
{
|
{
|
||||||
StartCoroutine(HowlRoutine());
|
StartCoroutine(HowlRoutine());
|
||||||
}
|
}
|
||||||
else if (RaceInput.AttackDown(1)) // Tasto destro (Heavy Claw)
|
else if (RaceInput.AttackDown(1) && FormMelee.TrySpendStamina(Player.m_localPlayer, FenrirConfig.FenringHeavyClawStamina.Value, Skills.SkillType.Unarmed)) // Tasto destro (Heavy Claw)
|
||||||
{
|
{
|
||||||
StartCoroutine(ClawRoutine("attack_claw1", FenrirConfig.FenringHeavyClawDamage.Value, 1.2f, 0.5f));
|
StartCoroutine(ClawRoutine("attack_claw1", FenrirConfig.FenringHeavyClawDamage.Value, 1.2f, 0.5f));
|
||||||
}
|
}
|
||||||
else if (RaceInput.AttackDown(0)) // Tasto sinistro
|
else if (RaceInput.AttackDown(0) && FormMelee.TrySpendStamina(Player.m_localPlayer, FenrirConfig.FenringLightClawStamina.Value, Skills.SkillType.Unarmed)) // Tasto sinistro
|
||||||
{
|
{
|
||||||
StartCoroutine(ClawRoutine("attack_claw0", FenrirConfig.FenringLightClawDamage.Value, 1.0f, 0.4f));
|
StartCoroutine(ClawRoutine("attack_claw0", FenrirConfig.FenringLightClawDamage.Value, 1.0f, 0.4f));
|
||||||
}
|
}
|
||||||
else if (RaceInput.AttackDown(2)) // Tasto centrale
|
else if (RaceInput.AttackDown(2) && FormMelee.TrySpendStamina(Player.m_localPlayer, FenrirConfig.FenringJumpAttackStamina.Value, Skills.SkillType.Unarmed)) // Tasto centrale
|
||||||
{
|
{
|
||||||
StartCoroutine(JumpAttackRoutine());
|
StartCoroutine(JumpAttackRoutine());
|
||||||
}
|
}
|
||||||
|
|
@ -690,7 +760,7 @@ namespace RacesOfValheim
|
||||||
|
|
||||||
private void ExecuteClawDamage(float baseDamage)
|
private void ExecuteClawDamage(float baseDamage)
|
||||||
{
|
{
|
||||||
if (Player.m_localPlayer == null) return;
|
if (Player.m_localPlayer == null || FormStagger.AttackInterrupted) return;
|
||||||
|
|
||||||
Vector3 playerPos = Player.m_localPlayer.transform.position;
|
Vector3 playerPos = Player.m_localPlayer.transform.position;
|
||||||
Vector3 attackPoint = playerPos + Player.m_localPlayer.transform.forward * 1.5f + Vector3.up * 1f;
|
Vector3 attackPoint = playerPos + Player.m_localPlayer.transform.forward * 1.5f + Vector3.up * 1f;
|
||||||
|
|
@ -704,6 +774,7 @@ namespace RacesOfValheim
|
||||||
Collider[] hits = Physics.OverlapSphere(attackPoint, attackRadius, layerMask);
|
Collider[] hits = Physics.OverlapSphere(attackPoint, attackRadius, layerMask);
|
||||||
FormMelee.LogSwing(FormLabel, hits.Length);
|
FormMelee.LogSwing(FormLabel, hits.Length);
|
||||||
System.Collections.Generic.HashSet<GameObject> hitObjects = new System.Collections.Generic.HashSet<GameObject>();
|
System.Collections.Generic.HashSet<GameObject> hitObjects = new System.Collections.Generic.HashSet<GameObject>();
|
||||||
|
bool hitCreature = false;
|
||||||
|
|
||||||
foreach (Collider hit in hits)
|
foreach (Collider hit in hits)
|
||||||
{
|
{
|
||||||
|
|
@ -753,10 +824,13 @@ namespace RacesOfValheim
|
||||||
FormMelee.LogHit(FormLabel, target, totalDamage);
|
FormMelee.LogHit(FormLabel, target, totalDamage);
|
||||||
target.Damage(hitData);
|
target.Damage(hitData);
|
||||||
FormMelee.GrantAdrenaline(target);
|
FormMelee.GrantAdrenaline(target);
|
||||||
|
if (target is Character) hitCreature = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (hitCreature) FormMelee.RaiseSkill(Skills.SkillType.Unarmed);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -805,47 +879,40 @@ namespace RacesOfValheim
|
||||||
// still falls through to StopFire() instead of leaving the flames running.
|
// still falls through to StopFire() instead of leaving the flames running.
|
||||||
bool canAct = RaceInput.Allowed;
|
bool canAct = RaceInput.Allowed;
|
||||||
|
|
||||||
// Fire attack on Right Click
|
// Fire attack on Right Click, held.
|
||||||
if (canAct && RaceInput.AttackHeld(1))
|
bool wantFire = canAct && RaceInput.AttackHeld(1) && !Player.m_localPlayer.IsStaggering();
|
||||||
|
if (wantFire && Player.m_localPlayer.GetEitr() <= 0f)
|
||||||
{
|
{
|
||||||
if (Player.m_localPlayer.GetEitr() > 0)
|
// Held with an empty pool. Until now this did nothing whatsoever: no
|
||||||
{
|
// flames, no sound, no reason given - and the form's own tier is Yagluth
|
||||||
if (!isShootingFire)
|
// while eitr is a Mistlands thing, so a Cultist meets this before it ever
|
||||||
{
|
// meets the fire.
|
||||||
StartFire();
|
SayNoEitr();
|
||||||
}
|
wantFire = false;
|
||||||
else
|
}
|
||||||
{
|
|
||||||
UpdateFire();
|
if (wantFire)
|
||||||
}
|
{
|
||||||
}
|
if (!isShootingFire) StartFire();
|
||||||
else
|
else UpdateFire();
|
||||||
{
|
|
||||||
// Held with an empty pool. Until now this did nothing whatsoever: no
|
|
||||||
// flames, no sound, no reason given - and the form's own tier is Yagluth
|
|
||||||
// while eitr is a Mistlands thing, so a Cultist meets this before it ever
|
|
||||||
// meets the fire.
|
|
||||||
SayNoEitr();
|
|
||||||
if (isShootingFire) StopFire();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else if (isShootingFire)
|
else if (isShootingFire)
|
||||||
{
|
{
|
||||||
StopFire();
|
StopFire();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (canAct && FenrirConfig.HowlKey.Value.IsDownIgnoringHeldKeys())
|
if (canAct && !isShootingFire && FenrirConfig.HowlKey.Value.IsDownIgnoringHeldKeys())
|
||||||
{
|
{
|
||||||
StartCoroutine(HowlRoutine());
|
StartCoroutine(HowlRoutine());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Attacks on Left Click
|
// Attacks on Left Click
|
||||||
if (canAct && RaceInput.AttackDown(0) && !isShootingFire)
|
if (canAct && RaceInput.AttackDown(0) && !isShootingFire && FormMelee.TrySpendStamina(Player.m_localPlayer, FenrirConfig.CultistClawStamina.Value, Skills.SkillType.Unarmed))
|
||||||
{
|
{
|
||||||
StartCoroutine(ClawRoutine()); // Single claw
|
StartCoroutine(ClawRoutine()); // Single claw
|
||||||
}
|
}
|
||||||
// Double claw on Middle Click
|
// Double claw on Middle Click
|
||||||
else if (canAct && RaceInput.AttackDown(2) && !isShootingFire)
|
else if (canAct && RaceInput.AttackDown(2) && !isShootingFire && FormMelee.TrySpendStamina(Player.m_localPlayer, FenrirConfig.CultistDoubleClawStamina.Value, Skills.SkillType.Unarmed))
|
||||||
{
|
{
|
||||||
StartCoroutine(DoubleClawRoutine());
|
StartCoroutine(DoubleClawRoutine());
|
||||||
}
|
}
|
||||||
|
|
@ -907,31 +974,54 @@ namespace RacesOfValheim
|
||||||
ModText.Get("rov_msg_fenrir_only_breath_comes_out_fire"));
|
ModText.Get("rov_msg_fenrir_only_breath_comes_out_fire"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// The breath runs on the flame clip (CultistBreathClip): pressed, the clip starts; the flames,
|
||||||
|
// the eitr drain and the damage begin at its own Hit point; released, the clip is cut.
|
||||||
|
private bool flaming;
|
||||||
|
private float fireStarted;
|
||||||
|
|
||||||
|
/// <summary>True while the local Cultist holds its breath attack, wind-up included. Read by
|
||||||
|
/// Cultist_BreathFacesCamera_Patch.</summary>
|
||||||
|
public static bool LocalBreathing { get; private set; }
|
||||||
|
|
||||||
private void StartFire()
|
private void StartFire()
|
||||||
{
|
{
|
||||||
if (Player.m_localPlayer == null || isShootingFire) return;
|
if (Player.m_localPlayer == null || isShootingFire) return;
|
||||||
|
|
||||||
isShootingFire = true;
|
isShootingFire = true;
|
||||||
|
LocalBreathing = true;
|
||||||
|
// Planted while it breathes, as the vanilla Cultist is: its controller has no walking
|
||||||
|
// version of the cast, so a moving Cultist slid along in the casting pose.
|
||||||
|
// Fenrir_FormHoldStill_Patch holds the player; turning to the camera still works.
|
||||||
|
FenrirForms.LocalAttacking = true;
|
||||||
|
flaming = false;
|
||||||
|
fireStarted = Time.time;
|
||||||
|
fireTimer = 0f;
|
||||||
FormAnimGuard.LeaveHowl(cultistAnim);
|
FormAnimGuard.LeaveHowl(cultistAnim);
|
||||||
cultistAnim.SetFloat("forward_speed", 0f);
|
cultistAnim.SetFloat("forward_speed", 0f);
|
||||||
cultistAnim.SetFloat("sideway_speed", 0f);
|
cultistAnim.SetFloat("sideway_speed", 0f);
|
||||||
cultistAnim.SetBool("attack_fire", true);
|
|
||||||
FenrirAttackSync.PublishFire(true);
|
FenrirAttackSync.PublishFire(true);
|
||||||
|
|
||||||
// Same cue the remote mirror plays - see the fire branch in the sync behaviour above.
|
// Same cue the remote mirror plays - see the fire branch in the sync behaviour above.
|
||||||
FenrirCreatureSound.PlayFireRoar(Player.m_localPlayer.transform.position);
|
FenrirCreatureSound.PlayFireRoar(Player.m_localPlayer.transform.position);
|
||||||
cultistAnim.SetTrigger("attack_flames");
|
cultistAnim.SetTrigger("attack_flames");
|
||||||
FenrirAttackSync.Publish("attack_flames");
|
FenrirAttackSync.Publish("attack_flames");
|
||||||
|
|
||||||
if (fireEffectInstance == null) fireEffectInstance = FenrirAttackSync.SpawnFlames(Player.m_localPlayer);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void UpdateFire()
|
private void UpdateFire()
|
||||||
{
|
{
|
||||||
Player.m_localPlayer.UseEitr(FenrirConfig.CultistFireEitrDrainPerSecond.Value * Time.deltaTime);
|
|
||||||
cultistAnim.SetFloat("forward_speed", 0f);
|
cultistAnim.SetFloat("forward_speed", 0f);
|
||||||
cultistAnim.SetFloat("sideway_speed", 0f);
|
cultistAnim.SetFloat("sideway_speed", 0f);
|
||||||
|
CultistBreathClip.Hold(cultistAnim);
|
||||||
|
|
||||||
|
if (!flaming)
|
||||||
|
{
|
||||||
|
if (!CultistBreathClip.FlamesDue(cultistAnim, fireStarted)) return;
|
||||||
|
flaming = true;
|
||||||
|
if (fireEffectInstance == null) fireEffectInstance = FenrirAttackSync.SpawnFlames(Player.m_localPlayer);
|
||||||
|
}
|
||||||
|
|
||||||
|
Player.m_localPlayer.UseEitr(FenrirConfig.CultistFireEitrDrainPerSecond.Value * Time.deltaTime);
|
||||||
|
|
||||||
fireTimer += Time.deltaTime;
|
fireTimer += Time.deltaTime;
|
||||||
if (fireTimer >= 0.2f) // Damage tick every 0.2s
|
if (fireTimer >= 0.2f) // Damage tick every 0.2s
|
||||||
{
|
{
|
||||||
|
|
@ -944,14 +1034,20 @@ namespace RacesOfValheim
|
||||||
private void OnDestroy()
|
private void OnDestroy()
|
||||||
{
|
{
|
||||||
if (isShootingFire) FenrirAttackSync.PublishFire(false);
|
if (isShootingFire) FenrirAttackSync.PublishFire(false);
|
||||||
|
if (isShootingFire) FenrirForms.LocalAttacking = false;
|
||||||
|
LocalBreathing = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void StopFire()
|
private void StopFire()
|
||||||
{
|
{
|
||||||
isShootingFire = false;
|
isShootingFire = false;
|
||||||
|
LocalBreathing = false;
|
||||||
|
FenrirForms.LocalAttacking = false;
|
||||||
|
flaming = false;
|
||||||
cultistAnim.ResetTrigger("attack_flames");
|
cultistAnim.ResetTrigger("attack_flames");
|
||||||
FenrirAttackSync.PublishFire(false);
|
FenrirAttackSync.PublishFire(false);
|
||||||
|
CultistBreathClip.Release(cultistAnim, Player.m_localPlayer);
|
||||||
|
|
||||||
if (fireEffectInstance != null)
|
if (fireEffectInstance != null)
|
||||||
{
|
{
|
||||||
Destroy(fireEffectInstance);
|
Destroy(fireEffectInstance);
|
||||||
|
|
@ -975,6 +1071,7 @@ namespace RacesOfValheim
|
||||||
Collider[] hits = Physics.OverlapSphere(attackPoint, attackRadius, layerMask);
|
Collider[] hits = Physics.OverlapSphere(attackPoint, attackRadius, layerMask);
|
||||||
FormMelee.LogSwing(FormLabel, hits.Length);
|
FormMelee.LogSwing(FormLabel, hits.Length);
|
||||||
System.Collections.Generic.HashSet<GameObject> hitObjects = new System.Collections.Generic.HashSet<GameObject>();
|
System.Collections.Generic.HashSet<GameObject> hitObjects = new System.Collections.Generic.HashSet<GameObject>();
|
||||||
|
bool hitCreature = false;
|
||||||
|
|
||||||
foreach (Collider hit in hits)
|
foreach (Collider hit in hits)
|
||||||
{
|
{
|
||||||
|
|
@ -1014,6 +1111,7 @@ namespace RacesOfValheim
|
||||||
FormMelee.LogHit(FormLabel, target, totalDamage);
|
FormMelee.LogHit(FormLabel, target, totalDamage);
|
||||||
target.Damage(hitData);
|
target.Damage(hitData);
|
||||||
FormMelee.GrantAdrenaline(target, 0.2f); // one 0.2s tick: a full hit per second of breath
|
FormMelee.GrantAdrenaline(target, 0.2f); // one 0.2s tick: a full hit per second of breath
|
||||||
|
if (target is Character) hitCreature = true;
|
||||||
|
|
||||||
if (ZNetScene.instance != null)
|
if (ZNetScene.instance != null)
|
||||||
{
|
{
|
||||||
|
|
@ -1023,6 +1121,8 @@ namespace RacesOfValheim
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (hitCreature) FormMelee.RaiseSkill(Skills.SkillType.ElementalMagic, 0.2f); // one 0.2s tick: a full swing's worth per second of breath
|
||||||
}
|
}
|
||||||
|
|
||||||
private IEnumerator ClawRoutine()
|
private IEnumerator ClawRoutine()
|
||||||
|
|
@ -1034,25 +1134,30 @@ namespace RacesOfValheim
|
||||||
cultistAnim.SetFloat("sideway_speed", 0f);
|
cultistAnim.SetFloat("sideway_speed", 0f);
|
||||||
|
|
||||||
// Per il Cultista usiamo esplicitamente il trigger dell'artigliata
|
// Per il Cultista usiamo esplicitamente il trigger dell'artigliata
|
||||||
|
int baseline = FenrirForms.AttackEvents;
|
||||||
|
float started = Time.time;
|
||||||
cultistAnim.SetTrigger("attack_claw");
|
cultistAnim.SetTrigger("attack_claw");
|
||||||
FenrirAttackSync.Publish("attack_claw", "sfx_fenring_claw_start");
|
FenrirAttackSync.Publish("attack_claw", "sfx_fenring_claw_start");
|
||||||
|
|
||||||
yield return new WaitForSeconds(0.4f);
|
// The blow lands on the clip's own Hit event (ClawAttackCultist: 0.64 s of 1.33 s), and
|
||||||
|
// the lock holds until the clip is over. A fixed 0.4 s hit and a 0.5 s lock used to land
|
||||||
|
// the damage before the claw swung and let the next click start a new one mid-swing.
|
||||||
|
yield return null;
|
||||||
|
float length = ClipLength(1.33f);
|
||||||
|
|
||||||
|
yield return WaitForHit(baseline, started);
|
||||||
PlaySFX("sfx_fenring_claw_start");
|
PlaySFX("sfx_fenring_claw_start");
|
||||||
|
|
||||||
ExecuteClawDamage(FenrirConfig.CultistClawDamage.Value);
|
ExecuteClawDamage(FenrirConfig.CultistClawDamage.Value);
|
||||||
|
|
||||||
float remainingTimeToIdle = 0.5f - 0.4f;
|
yield return WaitUntilClipEnds(length, started);
|
||||||
if (remainingTimeToIdle > 0)
|
|
||||||
{
|
|
||||||
yield return new WaitForSeconds(remainingTimeToIdle);
|
|
||||||
}
|
|
||||||
|
|
||||||
cultistAnim.ResetTrigger("attack_claw");
|
cultistAnim.ResetTrigger("attack_claw");
|
||||||
isAttacking = false;
|
isAttacking = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Each swipe of the double claw deals this share of Double Claw Damage. Two swipes give
|
||||||
|
// 120% of what the old single hit dealt: a little more, for a slower swing that can be cut short.
|
||||||
|
private const float DoubleClawHitShare = 0.6f;
|
||||||
|
|
||||||
private IEnumerator DoubleClawRoutine()
|
private IEnumerator DoubleClawRoutine()
|
||||||
{
|
{
|
||||||
isAttacking = true;
|
isAttacking = true;
|
||||||
|
|
@ -1061,27 +1166,66 @@ namespace RacesOfValheim
|
||||||
cultistAnim.SetFloat("forward_speed", 0f);
|
cultistAnim.SetFloat("forward_speed", 0f);
|
||||||
cultistAnim.SetFloat("sideway_speed", 0f);
|
cultistAnim.SetFloat("sideway_speed", 0f);
|
||||||
|
|
||||||
|
int baseline = FenrirForms.AttackEvents;
|
||||||
|
float started = Time.time;
|
||||||
cultistAnim.SetTrigger("attack_claw_double");
|
cultistAnim.SetTrigger("attack_claw_double");
|
||||||
FenrirAttackSync.Publish("attack_claw_double", "sfx_fenring_claw_start");
|
FenrirAttackSync.Publish("attack_claw_double", "sfx_fenring_claw_start");
|
||||||
|
|
||||||
// L'animazione double claw è più lunga, facciamo il danno un po' dopo
|
// DoubleClawAttackCultist carries two Hit events (0.64 s and 1.21 s of 1.83 s), one per
|
||||||
yield return new WaitForSeconds(0.6f);
|
// swipe. It used to deal one hit at a fixed 0.6 s, so the second swipe did nothing.
|
||||||
|
yield return null;
|
||||||
|
float length = ClipLength(1.83f);
|
||||||
|
float damage = FenrirConfig.CultistDoubleClawDamage.Value * DoubleClawHitShare;
|
||||||
|
|
||||||
|
yield return WaitForHit(baseline, started);
|
||||||
PlaySFX("sfx_fenring_claw_start");
|
PlaySFX("sfx_fenring_claw_start");
|
||||||
|
ExecuteClawDamage(damage);
|
||||||
|
|
||||||
ExecuteClawDamage(FenrirConfig.CultistDoubleClawDamage.Value);
|
yield return WaitForHit(baseline + 1, started, HitEventTimeout + 0.6f);
|
||||||
|
PlaySFX("sfx_fenring_claw_start");
|
||||||
// Attendiamo che l'animazione finisca (locking del giocatore)
|
ExecuteClawDamage(damage);
|
||||||
// L'animazione doppia del cultista dura circa 1.5 - 2 secondi
|
|
||||||
yield return new WaitForSeconds(1.2f);
|
|
||||||
|
|
||||||
|
yield return WaitUntilClipEnds(length, started);
|
||||||
cultistAnim.ResetTrigger("attack_claw_double");
|
cultistAnim.ResetTrigger("attack_claw_double");
|
||||||
isAttacking = false;
|
isAttacking = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Longest a swipe waits for its Hit event before landing anyway, measured from the trigger:
|
||||||
|
// a clip that never sends one must not leave the Cultist swinging at nothing.
|
||||||
|
private const float HitEventTimeout = 1.5f;
|
||||||
|
|
||||||
|
/// <summary>Waits until the clip has sent more than <paramref name="seen"/> hit events since
|
||||||
|
/// the trigger, or until the timeout.</summary>
|
||||||
|
private IEnumerator WaitForHit(int seen, float started, float timeout = HitEventTimeout)
|
||||||
|
{
|
||||||
|
while (FenrirForms.AttackEvents <= seen && Time.time - started < timeout)
|
||||||
|
{
|
||||||
|
yield return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>The attack clip's length, read a frame after its trigger, when the transition
|
||||||
|
/// into it has begun. <paramref name="fallback"/> is the clip's length in the game files.</summary>
|
||||||
|
private float ClipLength(float fallback)
|
||||||
|
{
|
||||||
|
AnimatorClipInfo[] clips = cultistAnim.IsInTransition(0)
|
||||||
|
? cultistAnim.GetNextAnimatorClipInfo(0)
|
||||||
|
: cultistAnim.GetCurrentAnimatorClipInfo(0);
|
||||||
|
if (clips != null && clips.Length > 0 && clips[0].clip != null) return clips[0].clip.length;
|
||||||
|
return fallback;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>Holds the lock until the clip has played out, clamped so a wrong reading can
|
||||||
|
/// neither cut a swing short nor freeze the form.</summary>
|
||||||
|
private IEnumerator WaitUntilClipEnds(float length, float started)
|
||||||
|
{
|
||||||
|
float remaining = Mathf.Clamp(length, 0.6f, 3f) - (Time.time - started);
|
||||||
|
if (remaining > 0f) yield return new WaitForSeconds(remaining);
|
||||||
|
}
|
||||||
|
|
||||||
private void ExecuteClawDamage(float baseDamage)
|
private void ExecuteClawDamage(float baseDamage)
|
||||||
{
|
{
|
||||||
if (Player.m_localPlayer == null) return;
|
if (Player.m_localPlayer == null || FormStagger.AttackInterrupted) return;
|
||||||
|
|
||||||
Vector3 playerPos = Player.m_localPlayer.transform.position;
|
Vector3 playerPos = Player.m_localPlayer.transform.position;
|
||||||
Vector3 attackPoint = playerPos + Player.m_localPlayer.transform.forward * 1.5f + Vector3.up * 1f;
|
Vector3 attackPoint = playerPos + Player.m_localPlayer.transform.forward * 1.5f + Vector3.up * 1f;
|
||||||
|
|
@ -1095,6 +1239,7 @@ namespace RacesOfValheim
|
||||||
Collider[] hits = Physics.OverlapSphere(attackPoint, attackRadius, layerMask);
|
Collider[] hits = Physics.OverlapSphere(attackPoint, attackRadius, layerMask);
|
||||||
FormMelee.LogSwing(FormLabel, hits.Length);
|
FormMelee.LogSwing(FormLabel, hits.Length);
|
||||||
System.Collections.Generic.HashSet<GameObject> hitObjects = new System.Collections.Generic.HashSet<GameObject>();
|
System.Collections.Generic.HashSet<GameObject> hitObjects = new System.Collections.Generic.HashSet<GameObject>();
|
||||||
|
bool hitCreature = false;
|
||||||
|
|
||||||
foreach (Collider hit in hits)
|
foreach (Collider hit in hits)
|
||||||
{
|
{
|
||||||
|
|
@ -1144,10 +1289,13 @@ namespace RacesOfValheim
|
||||||
FormMelee.LogHit(FormLabel, target, totalDamage);
|
FormMelee.LogHit(FormLabel, target, totalDamage);
|
||||||
target.Damage(hitData);
|
target.Damage(hitData);
|
||||||
FormMelee.GrantAdrenaline(target);
|
FormMelee.GrantAdrenaline(target);
|
||||||
|
if (target is Character) hitCreature = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (hitCreature) FormMelee.RaiseSkill(Skills.SkillType.Unarmed);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1194,15 +1342,15 @@ namespace RacesOfValheim
|
||||||
{
|
{
|
||||||
StartCoroutine(WolfHowlRoutine());
|
StartCoroutine(WolfHowlRoutine());
|
||||||
}
|
}
|
||||||
else if (RaceInput.AttackDown(0)) // Left Click
|
else if (RaceInput.AttackDown(0) && FormMelee.TrySpendStamina(Player.m_localPlayer, FenrirConfig.WolfAttack1Stamina.Value, Skills.SkillType.Unarmed)) // Left Click
|
||||||
{
|
{
|
||||||
StartCoroutine(WolfAttackRoutine("attack1", FenrirConfig.WolfAttack1Damage.Value, 0.6f, 0.2f));
|
StartCoroutine(WolfAttackRoutine("attack1", FenrirConfig.WolfAttack1Damage.Value, 0.6f, 0.2f));
|
||||||
}
|
}
|
||||||
else if (RaceInput.AttackDown(1)) // Right Click
|
else if (RaceInput.AttackDown(1) && FormMelee.TrySpendStamina(Player.m_localPlayer, FenrirConfig.WolfAttack2Stamina.Value, Skills.SkillType.Unarmed)) // Right Click
|
||||||
{
|
{
|
||||||
StartCoroutine(WolfAttackRoutine("attack2", FenrirConfig.WolfAttack2Damage.Value, 0.8f, 0.3f));
|
StartCoroutine(WolfAttackRoutine("attack2", FenrirConfig.WolfAttack2Damage.Value, 0.8f, 0.3f));
|
||||||
}
|
}
|
||||||
else if (RaceInput.AttackDown(2)) // Middle Click
|
else if (RaceInput.AttackDown(2) && FormMelee.TrySpendStamina(Player.m_localPlayer, FenrirConfig.WolfAttack3Stamina.Value, Skills.SkillType.Unarmed)) // Middle Click
|
||||||
{
|
{
|
||||||
StartCoroutine(WolfAttackRoutine("attack3", FenrirConfig.WolfAttack3Damage.Value, 1.0f, 0.4f));
|
StartCoroutine(WolfAttackRoutine("attack3", FenrirConfig.WolfAttack3Damage.Value, 1.0f, 0.4f));
|
||||||
}
|
}
|
||||||
|
|
@ -1295,7 +1443,7 @@ namespace RacesOfValheim
|
||||||
|
|
||||||
private void ExecuteBiteDamage(float baseDamage)
|
private void ExecuteBiteDamage(float baseDamage)
|
||||||
{
|
{
|
||||||
if (Player.m_localPlayer == null) return;
|
if (Player.m_localPlayer == null || FormStagger.AttackInterrupted) return;
|
||||||
|
|
||||||
Vector3 playerPos = Player.m_localPlayer.transform.position;
|
Vector3 playerPos = Player.m_localPlayer.transform.position;
|
||||||
// Il lupo è basso, abbassiamo l'altezza dell'attacco
|
// Il lupo è basso, abbassiamo l'altezza dell'attacco
|
||||||
|
|
@ -1310,6 +1458,7 @@ namespace RacesOfValheim
|
||||||
Collider[] hits = Physics.OverlapSphere(attackPoint, attackRadius, layerMask);
|
Collider[] hits = Physics.OverlapSphere(attackPoint, attackRadius, layerMask);
|
||||||
FormMelee.LogSwing(FormLabel, hits.Length);
|
FormMelee.LogSwing(FormLabel, hits.Length);
|
||||||
System.Collections.Generic.HashSet<GameObject> hitObjects = new System.Collections.Generic.HashSet<GameObject>();
|
System.Collections.Generic.HashSet<GameObject> hitObjects = new System.Collections.Generic.HashSet<GameObject>();
|
||||||
|
bool hitCreature = false;
|
||||||
|
|
||||||
foreach (Collider hit in hits)
|
foreach (Collider hit in hits)
|
||||||
{
|
{
|
||||||
|
|
@ -1359,10 +1508,13 @@ namespace RacesOfValheim
|
||||||
FormMelee.LogHit(FormLabel, target, totalDamage);
|
FormMelee.LogHit(FormLabel, target, totalDamage);
|
||||||
target.Damage(hitData);
|
target.Damage(hitData);
|
||||||
FormMelee.GrantAdrenaline(target);
|
FormMelee.GrantAdrenaline(target);
|
||||||
|
if (target is Character) hitCreature = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (hitCreature) FormMelee.RaiseSkill(Skills.SkillType.Unarmed);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1410,16 +1562,16 @@ namespace RacesOfValheim
|
||||||
{
|
{
|
||||||
StartCoroutine(UlvHowlRoutine());
|
StartCoroutine(UlvHowlRoutine());
|
||||||
}
|
}
|
||||||
else if (RaceInput.AttackDown(0)) // Left Click
|
else if (RaceInput.AttackDown(0) && FormMelee.TrySpendStamina(Player.m_localPlayer, FenrirConfig.UlvBiteStamina.Value, Skills.SkillType.Unarmed)) // Left Click
|
||||||
{
|
{
|
||||||
StartCoroutine(UlvAttackRoutine("attack_bite", FenrirConfig.UlvBiteDamage.Value, 0.6f, 0.2f));
|
StartCoroutine(UlvAttackRoutine("attack_bite", FenrirConfig.UlvBiteDamage.Value, 0.6f, 0.2f));
|
||||||
}
|
}
|
||||||
else if (RaceInput.AttackDown(1)) // Right Click
|
else if (RaceInput.AttackDown(1) && FormMelee.TrySpendStamina(Player.m_localPlayer, FenrirConfig.UlvHeavyBiteStamina.Value, Skills.SkillType.Unarmed)) // Right Click
|
||||||
{
|
{
|
||||||
// Right click uses bite but as a heavier attack since slash is moved to jump
|
// Right click uses bite but as a heavier attack since slash is moved to jump
|
||||||
StartCoroutine(UlvAttackRoutine("attack_bite", FenrirConfig.UlvHeavyBiteDamage.Value, 0.8f, 0.3f));
|
StartCoroutine(UlvAttackRoutine("attack_bite", FenrirConfig.UlvHeavyBiteDamage.Value, 0.8f, 0.3f));
|
||||||
}
|
}
|
||||||
else if (RaceInput.AttackDown(2)) // Middle Click
|
else if (RaceInput.AttackDown(2) && FormMelee.TrySpendStamina(Player.m_localPlayer, FenrirConfig.UlvJumpAttackStamina.Value, Skills.SkillType.Unarmed)) // Middle Click
|
||||||
{
|
{
|
||||||
StartCoroutine(UlvJumpAttackRoutine());
|
StartCoroutine(UlvJumpAttackRoutine());
|
||||||
}
|
}
|
||||||
|
|
@ -1504,7 +1656,7 @@ namespace RacesOfValheim
|
||||||
|
|
||||||
private void ExecuteBiteDamage(float baseDamage)
|
private void ExecuteBiteDamage(float baseDamage)
|
||||||
{
|
{
|
||||||
if (Player.m_localPlayer == null) return;
|
if (Player.m_localPlayer == null || FormStagger.AttackInterrupted) return;
|
||||||
|
|
||||||
Vector3 playerPos = Player.m_localPlayer.transform.position;
|
Vector3 playerPos = Player.m_localPlayer.transform.position;
|
||||||
Vector3 attackPoint = playerPos + Player.m_localPlayer.transform.forward * 1.5f + Vector3.up * 0.5f;
|
Vector3 attackPoint = playerPos + Player.m_localPlayer.transform.forward * 1.5f + Vector3.up * 0.5f;
|
||||||
|
|
@ -1518,6 +1670,7 @@ namespace RacesOfValheim
|
||||||
Collider[] hits = Physics.OverlapSphere(attackPoint, attackRadius, layerMask);
|
Collider[] hits = Physics.OverlapSphere(attackPoint, attackRadius, layerMask);
|
||||||
FormMelee.LogSwing(FormLabel, hits.Length);
|
FormMelee.LogSwing(FormLabel, hits.Length);
|
||||||
System.Collections.Generic.HashSet<GameObject> hitObjects = new System.Collections.Generic.HashSet<GameObject>();
|
System.Collections.Generic.HashSet<GameObject> hitObjects = new System.Collections.Generic.HashSet<GameObject>();
|
||||||
|
bool hitCreature = false;
|
||||||
|
|
||||||
foreach (Collider hit in hits)
|
foreach (Collider hit in hits)
|
||||||
{
|
{
|
||||||
|
|
@ -1567,10 +1720,13 @@ namespace RacesOfValheim
|
||||||
FormMelee.LogHit(FormLabel, target, totalDamage);
|
FormMelee.LogHit(FormLabel, target, totalDamage);
|
||||||
target.Damage(hitData);
|
target.Damage(hitData);
|
||||||
FormMelee.GrantAdrenaline(target);
|
FormMelee.GrantAdrenaline(target);
|
||||||
|
if (target is Character) hitCreature = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (hitCreature) FormMelee.RaiseSkill(Skills.SkillType.Unarmed);
|
||||||
}
|
}
|
||||||
|
|
||||||
private IEnumerator UlvJumpAttackRoutine()
|
private IEnumerator UlvJumpAttackRoutine()
|
||||||
|
|
@ -1621,4 +1777,160 @@ namespace RacesOfValheim
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The Cultist's breath, timed by its own clip. fenring_cultist_animator's attack_flames state
|
||||||
|
/// plays "Flame Spell Attack" (read offline with UnityPy, bundle c4210710): 3.5 s, the hands
|
||||||
|
/// light at 1.094 s (TrailOn), the vanilla flames come at 1.245 s (Hit) and are taken down at
|
||||||
|
/// 3.193 s. The state leaves for Movement only when the clip ends, so a short click used to
|
||||||
|
/// leave the Cultist standing with its arms up for the rest of the 3.5 s, breathing nothing.
|
||||||
|
///
|
||||||
|
/// Now the flames wait for the clip's Hit point, the arms are held in the casting pose for as
|
||||||
|
/// long as the button is, and letting go blends straight back to Movement. Shared by the
|
||||||
|
/// owner's Cultist and every onlooker's copy, so both play the same breath.
|
||||||
|
/// </summary>
|
||||||
|
internal static class CultistBreathClip
|
||||||
|
{
|
||||||
|
private static readonly int State = Animator.StringToHash("Base Layer.attack_flames");
|
||||||
|
private const string MovementState = "Base Layer.Movement";
|
||||||
|
|
||||||
|
// The clip's Hit event, where the vanilla Cultist's flames come out.
|
||||||
|
private const float FlamesAt = 1.245f;
|
||||||
|
|
||||||
|
// The throw itself: the Animator stops here while held. After it the vanilla Cultist lowers
|
||||||
|
// its arms while its fire flies on alone, so a pin at 2.6 s held an idle-looking pose.
|
||||||
|
private const float PinAt = 1.3f;
|
||||||
|
|
||||||
|
private const float Fade = 0.25f;
|
||||||
|
|
||||||
|
/// <summary>Seconds into the flame clip, or -1 while the Animator is in another state.</summary>
|
||||||
|
private static float ClipTime(Animator anim)
|
||||||
|
{
|
||||||
|
AnimatorStateInfo info = anim.IsInTransition(0) ? anim.GetNextAnimatorStateInfo(0) : anim.GetCurrentAnimatorStateInfo(0);
|
||||||
|
return info.fullPathHash == State ? info.normalizedTime * info.length : -1f;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>True once the clip has reached its Hit point. If the clip never started (another
|
||||||
|
/// state took the Animator), the same delay counted from the press stands in for it.</summary>
|
||||||
|
public static bool FlamesDue(Animator anim, float started)
|
||||||
|
{
|
||||||
|
float t = ClipTime(anim);
|
||||||
|
return t >= FlamesAt || (t < 0f && Time.time - started >= FlamesAt + 0.2f);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Holds the arms in the casting pose: once the clip reaches PinAt it is put back there every
|
||||||
|
/// frame. Not with Animator.speed = 0, which is what the troll's pin uses: the creature's own
|
||||||
|
/// CharacterAnimEvent sits on this model and sets speed back to 1 on every physics step while
|
||||||
|
/// the player is not in a vanilla attack, so the clip ran on to its end and the Cultist went
|
||||||
|
/// back to idle with the fire still pouring out.
|
||||||
|
/// </summary>
|
||||||
|
public static void Hold(Animator anim)
|
||||||
|
{
|
||||||
|
if (anim.IsInTransition(0)) return;
|
||||||
|
AnimatorStateInfo info = anim.GetCurrentAnimatorStateInfo(0);
|
||||||
|
if (info.fullPathHash != State || info.length <= 0f) return;
|
||||||
|
if (info.normalizedTime * info.length >= PinAt) anim.Play(State, 0, PinAt / info.length);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>Blends out of the clip, unless a stagger has taken over (FormStagger has fired
|
||||||
|
/// the form's own).</summary>
|
||||||
|
public static void Release(Animator anim, Player player)
|
||||||
|
{
|
||||||
|
if (anim == null) return;
|
||||||
|
if (ClipTime(anim) >= 0f && (player == null || !player.IsStaggering()))
|
||||||
|
anim.CrossFadeInFixedTime(MovementState, Fade, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Keeps the Cultist's breath in its hands, where the vanilla Cultist casts it from. fx_fenring_flames
|
||||||
|
/// has two emitters, "flames_world left" and "flames_world right", set 1.2 to 1.6 m ahead of
|
||||||
|
/// its own origin; spawned at the creature, the fire began that far in front of it. Each
|
||||||
|
/// emitter goes on its hand bone (fenring_cultist rig: .../LeftForeArm/LeftHand and the right
|
||||||
|
/// one), pointing where the player faces, so the two streams leave the palms and run forward.
|
||||||
|
/// The embers and the light sit between the hands. Placed every LateUpdate, after the form's
|
||||||
|
/// Animator has moved the arms. The same on every client's copy.
|
||||||
|
///
|
||||||
|
/// A form without hand bones keeps the whole effect at its mouth, as before.
|
||||||
|
/// </summary>
|
||||||
|
internal class CultistFlameFollow : MonoBehaviour
|
||||||
|
{
|
||||||
|
// Ahead of the palm, so the stream does not start inside the hand.
|
||||||
|
private const float AheadOfHand = 0.15f;
|
||||||
|
|
||||||
|
// The light, further ahead along the stream.
|
||||||
|
private const float LightAhead = 1.5f;
|
||||||
|
|
||||||
|
public Player Player;
|
||||||
|
private Transform mouth, leftHand, rightHand;
|
||||||
|
private Transform leftFlames, rightFlames, embers, light;
|
||||||
|
private bool partsFound;
|
||||||
|
private float nextLook;
|
||||||
|
|
||||||
|
private void LateUpdate()
|
||||||
|
{
|
||||||
|
if (Player == null) return;
|
||||||
|
|
||||||
|
if (!partsFound)
|
||||||
|
{
|
||||||
|
partsFound = true;
|
||||||
|
leftFlames = transform.Find("flames_world left");
|
||||||
|
rightFlames = transform.Find("flames_world right");
|
||||||
|
embers = transform.Find("FireEmbers");
|
||||||
|
light = transform.Find("Point light");
|
||||||
|
}
|
||||||
|
|
||||||
|
// The form can be rebuilt under the same flames; look again now and then if lost.
|
||||||
|
if ((leftHand == null || rightHand == null || mouth == null) && Time.time >= nextLook)
|
||||||
|
{
|
||||||
|
nextLook = Time.time + 0.5f;
|
||||||
|
leftHand = FindBone(Player, "LeftHand");
|
||||||
|
rightHand = FindBone(Player, "RightHand");
|
||||||
|
mouth = FenrirAttackSync.FindMouth(Player);
|
||||||
|
}
|
||||||
|
|
||||||
|
Quaternion facing = Player.transform.rotation;
|
||||||
|
transform.SetPositionAndRotation(FenrirAttackSync.MouthPoint(Player, mouth), facing);
|
||||||
|
if (leftHand == null || rightHand == null || leftFlames == null || rightFlames == null) return;
|
||||||
|
|
||||||
|
Vector3 forward = Player.transform.forward;
|
||||||
|
Vector3 left = leftHand.position + forward * AheadOfHand;
|
||||||
|
Vector3 right = rightHand.position + forward * AheadOfHand;
|
||||||
|
leftFlames.SetPositionAndRotation(left, facing);
|
||||||
|
rightFlames.SetPositionAndRotation(right, facing);
|
||||||
|
|
||||||
|
Vector3 between = (left + right) * 0.5f;
|
||||||
|
if (embers != null) embers.SetPositionAndRotation(between, facing);
|
||||||
|
if (light != null) light.position = between + forward * LightAhead;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Transform FindBone(Player player, string name)
|
||||||
|
{
|
||||||
|
foreach (Transform child in player.transform)
|
||||||
|
{
|
||||||
|
if (child.name == "Visual" || !child.gameObject.activeInHierarchy) continue;
|
||||||
|
foreach (Transform t in child.GetComponentsInChildren<Transform>())
|
||||||
|
{
|
||||||
|
if (t.name == name) return t;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Turns the Cultist toward the camera while it breathes fire, as vanilla turns a player who
|
||||||
|
/// blocks or draws a bow: Player.AlwaysRotateCamera answers true for those, and Character then
|
||||||
|
/// turns the body to the look direction at its own turn speed. The breath is not a vanilla
|
||||||
|
/// attack, so the body stayed facing wherever the movement keys had left it.
|
||||||
|
/// </summary>
|
||||||
|
[HarmonyPatch(typeof(Player), "AlwaysRotateCamera")]
|
||||||
|
public static class Cultist_BreathFacesCamera_Patch
|
||||||
|
{
|
||||||
|
public static void Postfix(Player __instance, ref bool __result)
|
||||||
|
{
|
||||||
|
if (!__result && __instance == Player.m_localPlayer && CultistFormBehavior.LocalBreathing) __result = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -38,15 +38,33 @@ namespace RacesOfValheim
|
||||||
public static ConfigEntry<float> SpeedBonusPerState;
|
public static ConfigEntry<float> SpeedBonusPerState;
|
||||||
public static ConfigEntry<float> JumpBonusPerState;
|
public static ConfigEntry<float> JumpBonusPerState;
|
||||||
public static ConfigEntry<float> SunSicknessDuration;
|
public static ConfigEntry<float> SunSicknessDuration;
|
||||||
|
public static ConfigEntry<float> SensesRadius;
|
||||||
|
|
||||||
// ─── Form buffs (applied while transformed) ───────────────────────────
|
// ─── Form buffs (applied while transformed) ───────────────────────────
|
||||||
public static ConfigEntry<float> FullFormSpeedBonus;
|
public static ConfigEntry<float> FullFormSpeedBonus;
|
||||||
public static ConfigEntry<float> FullFormJumpBonus;
|
public static ConfigEntry<float> FullFormJumpBonus;
|
||||||
public static ConfigEntry<float> FullFormFallDamageReduction;
|
public static ConfigEntry<float> FullFormFallDamageReduction;
|
||||||
public static ConfigEntry<float> WolfFormSpeedBonus;
|
public static ConfigEntry<float> WolfFormSpeedBonus;
|
||||||
|
public static ConfigEntry<float> UlvFormSpeedBonus;
|
||||||
|
public static ConfigEntry<float> FenringDamageReduction;
|
||||||
|
public static ConfigEntry<float> CultistExtraDamageTaken;
|
||||||
public static ConfigEntry<float> WolfFormFallDamageReduction;
|
public static ConfigEntry<float> WolfFormFallDamageReduction;
|
||||||
public static ConfigEntry<float> FormStaminaRegenMultiplier;
|
public static ConfigEntry<float> FormStaminaRegenMultiplier;
|
||||||
public static ConfigEntry<float> FormStaminaDrainReduction;
|
public static ConfigEntry<float> FormStaminaDrainReduction;
|
||||||
|
public static ConfigEntry<float> FormAdrenalineMultiplier;
|
||||||
|
|
||||||
|
// ─── Form attack stamina (base cost, before the Unarmed skill discount) ─
|
||||||
|
public static ConfigEntry<float> FenringLightClawStamina;
|
||||||
|
public static ConfigEntry<float> FenringHeavyClawStamina;
|
||||||
|
public static ConfigEntry<float> FenringJumpAttackStamina;
|
||||||
|
public static ConfigEntry<float> CultistClawStamina;
|
||||||
|
public static ConfigEntry<float> CultistDoubleClawStamina;
|
||||||
|
public static ConfigEntry<float> WolfAttack1Stamina;
|
||||||
|
public static ConfigEntry<float> WolfAttack2Stamina;
|
||||||
|
public static ConfigEntry<float> WolfAttack3Stamina;
|
||||||
|
public static ConfigEntry<float> UlvBiteStamina;
|
||||||
|
public static ConfigEntry<float> UlvHeavyBiteStamina;
|
||||||
|
public static ConfigEntry<float> UlvJumpAttackStamina;
|
||||||
|
|
||||||
// ─── Fenring form attacks ─────────────────────────────────────────────
|
// ─── Fenring form attacks ─────────────────────────────────────────────
|
||||||
public static ConfigEntry<float> FenringHeavyClawDamage;
|
public static ConfigEntry<float> FenringHeavyClawDamage;
|
||||||
|
|
@ -82,9 +100,6 @@ namespace RacesOfValheim
|
||||||
public static ConfigEntry<float> UlvAttackRadius;
|
public static ConfigEntry<float> UlvAttackRadius;
|
||||||
public static ConfigEntry<float> UlvPushForce;
|
public static ConfigEntry<float> UlvPushForce;
|
||||||
|
|
||||||
// ─── Debug ─────────────────────────────────────────────────────────────
|
|
||||||
public static ConfigEntry<bool> DebugFormHits;
|
|
||||||
|
|
||||||
// ─── Appearance (per player, never synced) ──────────────────────────────
|
// ─── Appearance (per player, never synced) ──────────────────────────────
|
||||||
public static ConfigEntry<bool> ReadyMessage;
|
public static ConfigEntry<bool> ReadyMessage;
|
||||||
public static ConfigEntry<bool> EyeGlow;
|
public static ConfigEntry<bool> EyeGlow;
|
||||||
|
|
@ -117,16 +132,30 @@ namespace RacesOfValheim
|
||||||
SunSicknessDuration = config.Bind(combat, "Sun Sickness Duration", 60f,
|
SunSicknessDuration = config.Bind(combat, "Sun Sickness Duration", 60f,
|
||||||
new ConfigDescription("Seconds of forced human form after being reverted by sunrise.", new AcceptableValueRange<float>(0f, 300f)));
|
new ConfigDescription("Seconds of forced human form after being reverted by sunrise.", new AcceptableValueRange<float>(0f, 300f)));
|
||||||
|
|
||||||
|
const string senses = "Fenrir - Superhuman Senses";
|
||||||
|
SensesRadius = config.Bind(senses, "Detection Radius", 100f,
|
||||||
|
new ConfigDescription("Meters within which nearby creatures glow green while you are in any form. The light itself follows the Aswid's Marker Light settings.", new AcceptableValueRange<float>(10f, 300f)));
|
||||||
|
|
||||||
const string buffs = "Fenrir - Form Buffs";
|
const string buffs = "Fenrir - Form Buffs";
|
||||||
BindNote(config, buffs, "Note: these values need a relog to take effect.");
|
BindNote(config, buffs, "Note: these values need a relog to take effect.");
|
||||||
FullFormSpeedBonus = config.Bind(buffs, "Full Form Speed Bonus", 1.0f,
|
// Each form has a job once all three are unlocked (Lexsonn's suggestion): the Ulv
|
||||||
new ConfigDescription("Speed multiplier bonus while in Fenring or Cultist form.", new AcceptableValueRange<float>(0f, 3f)));
|
// travels, the Fenring holds the line, the Cultist burns. The speed keys were renamed
|
||||||
|
// from "Full Form Speed Bonus" and "Wolf Form Speed Bonus" so a saved .cfg cannot keep
|
||||||
|
// the old order, where the Fenring outran the Ulv.
|
||||||
|
FullFormSpeedBonus = config.Bind(buffs, "Fenring And Cultist Speed Bonus", 0.5f,
|
||||||
|
new ConfigDescription("Speed multiplier bonus while in Fenring or Cultist form. 0.5 = 50% faster.", new AcceptableValueRange<float>(0f, 3f)));
|
||||||
FullFormJumpBonus = config.Bind(buffs, "Full Form Jump Bonus", 1.0f,
|
FullFormJumpBonus = config.Bind(buffs, "Full Form Jump Bonus", 1.0f,
|
||||||
new ConfigDescription("Jump multiplier bonus while in Fenring or Cultist form.", new AcceptableValueRange<float>(0f, 3f)));
|
new ConfigDescription("Jump multiplier bonus while in Fenring or Cultist form.", new AcceptableValueRange<float>(0f, 3f)));
|
||||||
FullFormFallDamageReduction = config.Bind(buffs, "Full Form Fall Damage Reduction", 1.0f,
|
FullFormFallDamageReduction = config.Bind(buffs, "Full Form Fall Damage Reduction", 1.0f,
|
||||||
new ConfigDescription("Fall damage reduction while in Fenring or Cultist form (1 = immune).", new AcceptableValueRange<float>(0f, 1f)));
|
new ConfigDescription("Fall damage reduction while in Fenring or Cultist form (1 = immune).", new AcceptableValueRange<float>(0f, 1f)));
|
||||||
WolfFormSpeedBonus = config.Bind(buffs, "Wolf Form Speed Bonus", 0.5f,
|
WolfFormSpeedBonus = config.Bind(buffs, "Wolf Speed Bonus", 0.5f,
|
||||||
new ConfigDescription("Speed multiplier bonus while in Wolf or Ulv form.", new AcceptableValueRange<float>(0f, 3f)));
|
new ConfigDescription("Speed multiplier bonus while in Wolf form, the G form before Moder.", new AcceptableValueRange<float>(0f, 3f)));
|
||||||
|
UlvFormSpeedBonus = config.Bind(buffs, "Ulv Speed Bonus", 1.0f,
|
||||||
|
new ConfigDescription("Speed multiplier bonus while in Ulv form. The fastest form by default: the one to travel in.", new AcceptableValueRange<float>(0f, 3f)));
|
||||||
|
FenringDamageReduction = config.Bind(buffs, "Fenring Damage Reduction", 0.3f,
|
||||||
|
new ConfigDescription("Share of every hit the Fenring shrugs off. 0.3 = 30% less damage taken.", new AcceptableValueRange<float>(0f, 0.9f)));
|
||||||
|
CultistExtraDamageTaken = config.Bind(buffs, "Cultist Extra Damage Taken", 0.25f,
|
||||||
|
new ConfigDescription("How much harder hits land on the Cultist. 0.25 = 25% more damage taken.", new AcceptableValueRange<float>(0f, 2f)));
|
||||||
WolfFormFallDamageReduction = config.Bind(buffs, "Wolf Form Fall Damage Reduction", 0.5f,
|
WolfFormFallDamageReduction = config.Bind(buffs, "Wolf Form Fall Damage Reduction", 0.5f,
|
||||||
new ConfigDescription("Fall damage reduction while in Wolf or Ulv form.", new AcceptableValueRange<float>(0f, 1f)));
|
new ConfigDescription("Fall damage reduction while in Wolf or Ulv form.", new AcceptableValueRange<float>(0f, 1f)));
|
||||||
FormStaminaRegenMultiplier = config.Bind(buffs, "Stamina Regen Multiplier", 1.3f,
|
FormStaminaRegenMultiplier = config.Bind(buffs, "Stamina Regen Multiplier", 1.3f,
|
||||||
|
|
@ -154,7 +183,7 @@ namespace RacesOfValheim
|
||||||
CultistClawDamage = config.Bind(cultist, "Claw Damage", 85f,
|
CultistClawDamage = config.Bind(cultist, "Claw Damage", 85f,
|
||||||
new ConfigDescription("Base damage of the single claw (Left Mouse), before the Unarmed skill bonus.", new AcceptableValueRange<float>(0f, 500f)));
|
new ConfigDescription("Base damage of the single claw (Left Mouse), before the Unarmed skill bonus.", new AcceptableValueRange<float>(0f, 500f)));
|
||||||
CultistDoubleClawDamage = config.Bind(cultist, "Double Claw Damage", 140f,
|
CultistDoubleClawDamage = config.Bind(cultist, "Double Claw Damage", 140f,
|
||||||
new ConfigDescription("Base damage of the double claw (Middle Mouse), before the Unarmed skill bonus.", new AcceptableValueRange<float>(0f, 500f)));
|
new ConfigDescription("Base damage of the double claw (Middle Mouse), before the Unarmed skill bonus. Each of its two swipes deals 60% of it.", new AcceptableValueRange<float>(0f, 500f)));
|
||||||
CultistAttackRadius = config.Bind(cultist, "Claw Attack Radius", 2.5f,
|
CultistAttackRadius = config.Bind(cultist, "Claw Attack Radius", 2.5f,
|
||||||
new ConfigDescription("Hit-sweep radius for both claw attacks.", new AcceptableValueRange<float>(1f, 10f)));
|
new ConfigDescription("Hit-sweep radius for both claw attacks.", new AcceptableValueRange<float>(1f, 10f)));
|
||||||
CultistPushForce = config.Bind(cultist, "Claw Push Force", 30f,
|
CultistPushForce = config.Bind(cultist, "Claw Push Force", 30f,
|
||||||
|
|
@ -194,6 +223,35 @@ namespace RacesOfValheim
|
||||||
UlvPushForce = config.Bind(ulv, "Push Force", 25f,
|
UlvPushForce = config.Bind(ulv, "Push Force", 25f,
|
||||||
new ConfigDescription("Knockback applied on a hit.", new AcceptableValueRange<float>(0f, 100f)));
|
new ConfigDescription("Knockback applied on a hit.", new AcceptableValueRange<float>(0f, 100f)));
|
||||||
|
|
||||||
|
// Form attack stamina, beside each form's damage. Lower than a weapon's on purpose: the
|
||||||
|
// forms pay less per swing and fill the adrenaline bar faster instead (Form Adrenaline
|
||||||
|
// Multiplier). For scale, vanilla fists cost 4, Bjorn claws 6, Fenris claws 10.
|
||||||
|
const string staminaNote = " Base stamina, cut by up to a third with the Unarmed skill as a weapon's is. 0 makes it free.";
|
||||||
|
FormAdrenalineMultiplier = config.Bind(buffs, "Form Adrenaline Multiplier", 1.5f,
|
||||||
|
new ConfigDescription("Adrenaline per form hit, times the bare-handed amount, in any Fenrir form.", new AcceptableValueRange<float>(0f, 5f)));
|
||||||
|
FenringLightClawStamina = config.Bind(fenring, "Light Claw Stamina", 6f,
|
||||||
|
new ConfigDescription("Stamina for the light claw (Left Mouse)." + staminaNote, new AcceptableValueRange<float>(0f, 50f)));
|
||||||
|
FenringHeavyClawStamina = config.Bind(fenring, "Heavy Claw Stamina", 10f,
|
||||||
|
new ConfigDescription("Stamina for the heavy claw (Right Mouse)." + staminaNote, new AcceptableValueRange<float>(0f, 50f)));
|
||||||
|
FenringJumpAttackStamina = config.Bind(fenring, "Jump Attack Stamina", 16f,
|
||||||
|
new ConfigDescription("Stamina for the leaping attack (Middle Mouse)." + staminaNote, new AcceptableValueRange<float>(0f, 50f)));
|
||||||
|
CultistClawStamina = config.Bind(cultist, "Claw Stamina", 6f,
|
||||||
|
new ConfigDescription("Stamina for the single claw (Left Mouse)." + staminaNote, new AcceptableValueRange<float>(0f, 50f)));
|
||||||
|
CultistDoubleClawStamina = config.Bind(cultist, "Double Claw Stamina", 12f,
|
||||||
|
new ConfigDescription("Stamina for the double claw (Middle Mouse)." + staminaNote, new AcceptableValueRange<float>(0f, 50f)));
|
||||||
|
WolfAttack1Stamina = config.Bind(wolf, "Attack 1 Stamina", 4f,
|
||||||
|
new ConfigDescription("Stamina for the Left Mouse attack." + staminaNote, new AcceptableValueRange<float>(0f, 50f)));
|
||||||
|
WolfAttack2Stamina = config.Bind(wolf, "Attack 2 Stamina", 6f,
|
||||||
|
new ConfigDescription("Stamina for the Right Mouse attack." + staminaNote, new AcceptableValueRange<float>(0f, 50f)));
|
||||||
|
WolfAttack3Stamina = config.Bind(wolf, "Attack 3 Stamina", 10f,
|
||||||
|
new ConfigDescription("Stamina for the Middle Mouse attack." + staminaNote, new AcceptableValueRange<float>(0f, 50f)));
|
||||||
|
UlvBiteStamina = config.Bind(ulv, "Bite Stamina", 5f,
|
||||||
|
new ConfigDescription("Stamina for the Left Mouse bite." + staminaNote, new AcceptableValueRange<float>(0f, 50f)));
|
||||||
|
UlvHeavyBiteStamina = config.Bind(ulv, "Heavy Bite Stamina", 8f,
|
||||||
|
new ConfigDescription("Stamina for the Right Mouse bite." + staminaNote, new AcceptableValueRange<float>(0f, 50f)));
|
||||||
|
UlvJumpAttackStamina = config.Bind(ulv, "Jump Attack Stamina", 14f,
|
||||||
|
new ConfigDescription("Stamina for the leaping Middle Mouse attack." + staminaNote, new AcceptableValueRange<float>(0f, 50f)));
|
||||||
|
|
||||||
// The whole section stays local - see ConfigSync.LocalSections.
|
// The whole section stays local - see ConfigSync.LocalSections.
|
||||||
const string appearance = "Fenrir - Appearance";
|
const string appearance = "Fenrir - Appearance";
|
||||||
ReadyMessage = config.Bind(appearance, "Ready Message", true,
|
ReadyMessage = config.Bind(appearance, "Ready Message", true,
|
||||||
|
|
@ -207,10 +265,6 @@ namespace RacesOfValheim
|
||||||
// Tried at 1.2 in game: the orange was too strong. 0.9 checked and kept.
|
// Tried at 1.2 in game: the orange was too strong. 0.9 checked and kept.
|
||||||
EyeReadyStrength = config.Bind(appearance, "Eye Ready Strength", 0.9f,
|
EyeReadyStrength = config.Bind(appearance, "Eye Ready Strength", 0.9f,
|
||||||
new ConfigDescription("Glow at night while a form is ready.", new AcceptableValueRange<float>(0f, 3f)));
|
new ConfigDescription("Glow at night while a form is ready.", new AcceptableValueRange<float>(0f, 3f)));
|
||||||
|
|
||||||
// "debug" in the key keeps it local - see ConfigSync.
|
|
||||||
DebugFormHits = config.Bind("Fenrir - Debug", "Debug: Log Form Hits", false,
|
|
||||||
new ConfigDescription("Writes one log line per claw or bite: what was in reach, what it hit, and why anything was skipped. For bug reports about attacks that do no damage."));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,16 @@ namespace RacesOfValheim
|
||||||
/// form's own routines, and on every revert.</summary>
|
/// form's own routines, and on every revert.</summary>
|
||||||
public static bool LocalAttacking { get; set; }
|
public static bool LocalAttacking { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// How many hit events the local form's clips have fired: the creature's own "Hit" event,
|
||||||
|
/// which CharacterAnimEvent hands to the player's OnAttackTrigger, and BlockPlayerAttackTriggerPatch
|
||||||
|
/// counts here instead of letting it through. A swing waits for this to move, so its damage
|
||||||
|
/// lands on the clip's own blow (TrolTrueFormModel.AttackEvents, the same idea).
|
||||||
|
/// </summary>
|
||||||
|
public static int AttackEvents { get; private set; }
|
||||||
|
|
||||||
|
public static void NotifyAttackTrigger() => AttackEvents++;
|
||||||
|
|
||||||
public static bool LocalInForm(Character character)
|
public static bool LocalInForm(Character character)
|
||||||
{
|
{
|
||||||
if (character == null || character != Player.m_localPlayer) return false;
|
if (character == null || character != Player.m_localPlayer) return false;
|
||||||
|
|
@ -332,7 +342,7 @@ namespace RacesOfValheim
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static void LogMiss(string form, Collider hit, string reason)
|
public static void LogMiss(string form, Collider hit, string reason)
|
||||||
{
|
{
|
||||||
if (!FenrirConfig.DebugFormHits.Value) return;
|
if (!DebugConfig.LogFormHits.Value) return;
|
||||||
Jotunn.Logger.LogInfo($"[FenrirForm] {form} swing skipped '{hit.name}' (layer {LayerMask.LayerToName(hit.gameObject.layer)}): {reason}.");
|
Jotunn.Logger.LogInfo($"[FenrirForm] {form} swing skipped '{hit.name}' (layer {LayerMask.LayerToName(hit.gameObject.layer)}): {reason}.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -353,19 +363,87 @@ namespace RacesOfValheim
|
||||||
|
|
||||||
ItemDrop unarmed = player.m_unarmedWeapon;
|
ItemDrop unarmed = player.m_unarmedWeapon;
|
||||||
float perHit = unarmed != null ? unarmed.m_itemData.m_shared.m_attack.m_attackAdrenaline : 1f;
|
float perHit = unarmed != null ? unarmed.m_itemData.m_shared.m_attack.m_attackAdrenaline : 1f;
|
||||||
|
// The Fenrir forms trade cheaper swings for a faster bar; the other races' forms do not.
|
||||||
|
if (FenrirForms.LocalInForm(player)) perHit *= FenrirConfig.FormAdrenalineMultiplier.Value;
|
||||||
player.AddAdrenaline(perHit * character.m_enemyAdrenalineMultiplier * scale);
|
player.AddAdrenaline(perHit * character.m_enemyAdrenalineMultiplier * scale);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The skill experience vanilla gives for a weapon hit, which a hand-built hit never got.
|
||||||
|
/// Vanilla raises the skill inside Attack (once per swing that landed on a creature) and
|
||||||
|
/// inside Projectile.OnHit; Character.Damage never does, so a form that calls Damage
|
||||||
|
/// directly left its skill at whatever level the player brought in. Call it once per
|
||||||
|
/// swing or tick, after the loop, never once per target. amount lets a damage-over-time
|
||||||
|
/// tick pay a fraction of a swing.
|
||||||
|
/// </summary>
|
||||||
|
public static void RaiseSkill(Skills.SkillType skill, float amount = 1f)
|
||||||
|
{
|
||||||
|
Player player = Player.m_localPlayer;
|
||||||
|
if (player == null || amount <= 0f) return;
|
||||||
|
player.RaiseSkill(skill, amount);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Charges a form attack's stamina the way vanilla charges a weapon's (Attack.GetAttackStamina):
|
||||||
|
/// the equipment modifier, status effects (meads, race passives), then up to a third off with
|
||||||
|
/// the attack's skill. Without enough, the attack does not start and the stamina bar flashes,
|
||||||
|
/// as it does for a weapon. A cost of 0 is free and always goes through.
|
||||||
|
/// A staggered player cannot attack at all, and an attack that may start is marked for
|
||||||
|
/// FormStagger, so a stagger before its hit cancels it.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>True if the attack may start; the stamina is already spent.</returns>
|
||||||
|
public static bool TrySpendStamina(Player player, float baseCost, Skills.SkillType skill)
|
||||||
|
{
|
||||||
|
if (player != null && player.IsStaggering()) return false;
|
||||||
|
FormStagger.MarkAttack();
|
||||||
|
if (player == null || baseCost <= 0f) return true;
|
||||||
|
|
||||||
|
float cost = baseCost * (1f + player.GetEquipmentAttackStaminaModifier());
|
||||||
|
player.GetSEMan().ModifyAttackStaminaUsage(cost, ref cost);
|
||||||
|
cost -= cost * 0.33f * player.GetSkillFactor(skill);
|
||||||
|
if (cost <= 0f) return true;
|
||||||
|
|
||||||
|
if (!player.HaveStamina(cost + 0.1f))
|
||||||
|
{
|
||||||
|
if (player == Player.m_localPlayer && Hud.instance != null) Hud.instance.StaminaBarEmptyFlash();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
player.UseStamina(cost);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static readonly System.Collections.Generic.Dictionary<string, ItemDrop.ItemData.SharedData> weapons =
|
||||||
|
new System.Collections.Generic.Dictionary<string, ItemDrop.ItemData.SharedData>();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// A creature's own attack item (dragon_bite, SeekerBrute_ram...), read once and cached,
|
||||||
|
/// null if the game has none by that name. A hand-built swing skips Attack, and Attack is
|
||||||
|
/// where vanilla plays the item's m_triggerEffect and m_hitEffect, so a form that wants the
|
||||||
|
/// creature's real swing and impact sounds plays them from here.
|
||||||
|
/// </summary>
|
||||||
|
public static ItemDrop.ItemData.SharedData CreatureWeapon(string prefabName)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(prefabName)) return null;
|
||||||
|
if (weapons.TryGetValue(prefabName, out ItemDrop.ItemData.SharedData cached)) return cached;
|
||||||
|
|
||||||
|
GameObject prefab = Jotunn.Managers.PrefabManager.Cache.GetPrefab<GameObject>(prefabName);
|
||||||
|
ItemDrop.ItemData.SharedData shared = prefab != null ? prefab.GetComponent<ItemDrop>()?.m_itemData?.m_shared : null;
|
||||||
|
if (shared == null) Jotunn.Logger.LogWarning($"[FormMelee] No attack item '{prefabName}'; that swing stays silent.");
|
||||||
|
weapons[prefabName] = shared;
|
||||||
|
return shared;
|
||||||
|
}
|
||||||
|
|
||||||
public static void LogHit(string form, IDestructible target, float damage)
|
public static void LogHit(string form, IDestructible target, float damage)
|
||||||
{
|
{
|
||||||
if (!FenrirConfig.DebugFormHits.Value) return;
|
if (!DebugConfig.LogFormHits.Value) return;
|
||||||
string name = target is MonoBehaviour behaviour && behaviour != null ? behaviour.name : target.ToString();
|
string name = target is MonoBehaviour behaviour && behaviour != null ? behaviour.name : target.ToString();
|
||||||
Jotunn.Logger.LogInfo($"[FenrirForm] {form} swing hit '{name}' for {damage:0}.");
|
Jotunn.Logger.LogInfo($"[FenrirForm] {form} swing hit '{name}' for {damage:0}.");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void LogSwing(string form, int candidates)
|
public static void LogSwing(string form, int candidates)
|
||||||
{
|
{
|
||||||
if (!FenrirConfig.DebugFormHits.Value) return;
|
if (!DebugConfig.LogFormHits.Value) return;
|
||||||
Jotunn.Logger.LogInfo($"[FenrirForm] {form} swing: {candidates} collider(s) in reach.");
|
Jotunn.Logger.LogInfo($"[FenrirForm] {form} swing: {candidates} collider(s) in reach.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -56,7 +56,9 @@ namespace RacesOfValheim
|
||||||
{
|
{
|
||||||
public static bool Prefix(Humanoid __instance)
|
public static bool Prefix(Humanoid __instance)
|
||||||
{
|
{
|
||||||
return !FenrirForms.LocalInForm(__instance);
|
if (!FenrirForms.LocalInForm(__instance)) return true;
|
||||||
|
FenrirForms.NotifyAttackTrigger();
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -76,7 +76,7 @@ namespace RacesOfValheim {
|
||||||
cultistCdSE.m_icon = fenringTrophyIcon;
|
cultistCdSE.m_icon = fenringTrophyIcon;
|
||||||
ItemManager.Instance.AddStatusEffect(new CustomStatusEffect(cultistCdSE, fixReference: false));
|
ItemManager.Instance.AddStatusEffect(new CustomStatusEffect(cultistCdSE, fixReference: false));
|
||||||
|
|
||||||
formBuffSE = ScriptableObject.CreateInstance<SE_Stats>();
|
formBuffSE = ScriptableObject.CreateInstance<SE_FenrirFormBuff>();
|
||||||
formBuffSE.name = "SE_FenrirForm";
|
formBuffSE.name = "SE_FenrirForm";
|
||||||
formBuffSE.m_name = "$rov_se_fenrir_form_name";
|
formBuffSE.m_name = "$rov_se_fenrir_form_name";
|
||||||
formBuffSE.m_speedModifier = FenrirConfig.FullFormSpeedBonus.Value;
|
formBuffSE.m_speedModifier = FenrirConfig.FullFormSpeedBonus.Value;
|
||||||
|
|
@ -87,7 +87,7 @@ namespace RacesOfValheim {
|
||||||
formBuffSE.m_icon = fenringTrophyIcon;
|
formBuffSE.m_icon = fenringTrophyIcon;
|
||||||
ItemManager.Instance.AddStatusEffect(new CustomStatusEffect(formBuffSE, fixReference: false));
|
ItemManager.Instance.AddStatusEffect(new CustomStatusEffect(formBuffSE, fixReference: false));
|
||||||
|
|
||||||
cultistFormBuffSE = ScriptableObject.CreateInstance<SE_Stats>();
|
cultistFormBuffSE = ScriptableObject.CreateInstance<SE_FenrirFormBuff>();
|
||||||
cultistFormBuffSE.name = "SE_CultistForm";
|
cultistFormBuffSE.name = "SE_CultistForm";
|
||||||
cultistFormBuffSE.m_name = "$rov_se_fenrir_cultistform_name";
|
cultistFormBuffSE.m_name = "$rov_se_fenrir_cultistform_name";
|
||||||
cultistFormBuffSE.m_speedModifier = FenrirConfig.FullFormSpeedBonus.Value;
|
cultistFormBuffSE.m_speedModifier = FenrirConfig.FullFormSpeedBonus.Value;
|
||||||
|
|
@ -98,7 +98,7 @@ namespace RacesOfValheim {
|
||||||
cultistFormBuffSE.m_icon = fenringTrophyIcon;
|
cultistFormBuffSE.m_icon = fenringTrophyIcon;
|
||||||
ItemManager.Instance.AddStatusEffect(new CustomStatusEffect(cultistFormBuffSE, fixReference: false));
|
ItemManager.Instance.AddStatusEffect(new CustomStatusEffect(cultistFormBuffSE, fixReference: false));
|
||||||
|
|
||||||
wolfFormBuffSE = ScriptableObject.CreateInstance<SE_Stats>();
|
wolfFormBuffSE = ScriptableObject.CreateInstance<SE_FenrirFormBuff>();
|
||||||
wolfFormBuffSE.name = "SE_WolfForm";
|
wolfFormBuffSE.name = "SE_WolfForm";
|
||||||
wolfFormBuffSE.m_name = "$rov_se_fenrir_wolfform_name";
|
wolfFormBuffSE.m_name = "$rov_se_fenrir_wolfform_name";
|
||||||
wolfFormBuffSE.m_speedModifier = FenrirConfig.WolfFormSpeedBonus.Value;
|
wolfFormBuffSE.m_speedModifier = FenrirConfig.WolfFormSpeedBonus.Value;
|
||||||
|
|
@ -109,6 +109,16 @@ namespace RacesOfValheim {
|
||||||
ItemManager.Instance.AddStatusEffect(new CustomStatusEffect(wolfFormBuffSE, fixReference: false));
|
ItemManager.Instance.AddStatusEffect(new CustomStatusEffect(wolfFormBuffSE, fixReference: false));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Set on the live copy each time a form is taken, not on the registered template: the Wolf
|
||||||
|
// and the Ulv share SE_WolfForm but not a speed, and a changed value applies at the next
|
||||||
|
// transform instead of after a relog.
|
||||||
|
private static void SetFormBuff(StatusEffect se, float speedBonus, float damageTakenFactor)
|
||||||
|
{
|
||||||
|
if (!(se is SE_FenrirFormBuff buff)) return;
|
||||||
|
buff.m_speedModifier = speedBonus;
|
||||||
|
buff.m_damageTakenFactor = damageTakenFactor;
|
||||||
|
}
|
||||||
|
|
||||||
private void Update()
|
private void Update()
|
||||||
{
|
{
|
||||||
if (Player.m_localPlayer == null || EnvMan.instance == null) return;
|
if (Player.m_localPlayer == null || EnvMan.instance == null) return;
|
||||||
|
|
@ -164,6 +174,10 @@ namespace RacesOfValheim {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// The hunter's senses, shared with the Aswid: every form has them, the human does not.
|
||||||
|
if (isTransformed) HunterSenses.Tick(FenrirConfig.SensesRadius.Value);
|
||||||
|
else HunterSenses.Clear();
|
||||||
|
|
||||||
if (!RaceInput.Allowed) return;
|
if (!RaceInput.Allowed) return;
|
||||||
|
|
||||||
int state = BossProgressionManager.GetCurrentProgressionState();
|
int state = BossProgressionManager.GetCurrentProgressionState();
|
||||||
|
|
@ -412,6 +426,7 @@ namespace RacesOfValheim {
|
||||||
private IEnumerator RevertToHumanRoutine()
|
private IEnumerator RevertToHumanRoutine()
|
||||||
{
|
{
|
||||||
isTransformingSequence = true;
|
isTransformingSequence = true;
|
||||||
|
HunterSenses.Clear();
|
||||||
|
|
||||||
if (currentTransformation != null)
|
if (currentTransformation != null)
|
||||||
{
|
{
|
||||||
|
|
@ -545,6 +560,7 @@ namespace RacesOfValheim {
|
||||||
Player.m_localPlayer.GetSEMan().AddStatusEffect("SE_WolfForm".GetStableHashCode(), true);
|
Player.m_localPlayer.GetSEMan().AddStatusEffect("SE_WolfForm".GetStableHashCode(), true);
|
||||||
var se = Player.m_localPlayer.GetSEMan().GetStatusEffect("SE_WolfForm".GetStableHashCode());
|
var se = Player.m_localPlayer.GetSEMan().GetStatusEffect("SE_WolfForm".GetStableHashCode());
|
||||||
if (se != null) se.m_ttl = ttl;
|
if (se != null) se.m_ttl = ttl;
|
||||||
|
SetFormBuff(se, FenrirConfig.UlvFormSpeedBonus.Value, 1f);
|
||||||
Player.m_localPlayer.Message(MessageHud.MessageType.Center, ModText.Get("rov_msg_fenrir_are_ulv"));
|
Player.m_localPlayer.Message(MessageHud.MessageType.Center, ModText.Get("rov_msg_fenrir_are_ulv"));
|
||||||
}
|
}
|
||||||
else if (prefabName == "Wolf")
|
else if (prefabName == "Wolf")
|
||||||
|
|
@ -553,6 +569,7 @@ namespace RacesOfValheim {
|
||||||
Player.m_localPlayer.GetSEMan().AddStatusEffect("SE_WolfForm".GetStableHashCode(), true);
|
Player.m_localPlayer.GetSEMan().AddStatusEffect("SE_WolfForm".GetStableHashCode(), true);
|
||||||
var se = Player.m_localPlayer.GetSEMan().GetStatusEffect("SE_WolfForm".GetStableHashCode());
|
var se = Player.m_localPlayer.GetSEMan().GetStatusEffect("SE_WolfForm".GetStableHashCode());
|
||||||
if (se != null) se.m_ttl = ttl;
|
if (se != null) se.m_ttl = ttl;
|
||||||
|
SetFormBuff(se, FenrirConfig.WolfFormSpeedBonus.Value, 1f);
|
||||||
Player.m_localPlayer.Message(MessageHud.MessageType.Center, ModText.Get("rov_msg_fenrir_are_wolf"));
|
Player.m_localPlayer.Message(MessageHud.MessageType.Center, ModText.Get("rov_msg_fenrir_are_wolf"));
|
||||||
}
|
}
|
||||||
else if (prefabName == "Fenring_Cultist")
|
else if (prefabName == "Fenring_Cultist")
|
||||||
|
|
@ -561,6 +578,7 @@ namespace RacesOfValheim {
|
||||||
Player.m_localPlayer.GetSEMan().AddStatusEffect("SE_CultistForm".GetStableHashCode(), true);
|
Player.m_localPlayer.GetSEMan().AddStatusEffect("SE_CultistForm".GetStableHashCode(), true);
|
||||||
var se = Player.m_localPlayer.GetSEMan().GetStatusEffect("SE_CultistForm".GetStableHashCode());
|
var se = Player.m_localPlayer.GetSEMan().GetStatusEffect("SE_CultistForm".GetStableHashCode());
|
||||||
if (se != null) se.m_ttl = ttl;
|
if (se != null) se.m_ttl = ttl;
|
||||||
|
SetFormBuff(se, FenrirConfig.FullFormSpeedBonus.Value, 1f + FenrirConfig.CultistExtraDamageTaken.Value);
|
||||||
Player.m_localPlayer.Message(MessageHud.MessageType.Center, ModText.Get("rov_msg_fenrir_are_cultist"));
|
Player.m_localPlayer.Message(MessageHud.MessageType.Center, ModText.Get("rov_msg_fenrir_are_cultist"));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
@ -569,6 +587,7 @@ namespace RacesOfValheim {
|
||||||
Player.m_localPlayer.GetSEMan().AddStatusEffect("SE_FenrirForm".GetStableHashCode(), true);
|
Player.m_localPlayer.GetSEMan().AddStatusEffect("SE_FenrirForm".GetStableHashCode(), true);
|
||||||
var se = Player.m_localPlayer.GetSEMan().GetStatusEffect("SE_FenrirForm".GetStableHashCode());
|
var se = Player.m_localPlayer.GetSEMan().GetStatusEffect("SE_FenrirForm".GetStableHashCode());
|
||||||
if (se != null) se.m_ttl = ttl;
|
if (se != null) se.m_ttl = ttl;
|
||||||
|
SetFormBuff(se, FenrirConfig.FullFormSpeedBonus.Value, 1f - FenrirConfig.FenringDamageReduction.Value);
|
||||||
Player.m_localPlayer.Message(MessageHud.MessageType.Center, ModText.Get("rov_msg_fenrir_are_fenring"));
|
Player.m_localPlayer.Message(MessageHud.MessageType.Center, ModText.Get("rov_msg_fenrir_are_fenring"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,23 @@ namespace RacesOfValheim
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// A form's buff, plus a scale on the hits it takes: the Fenring holds the line on less, the
|
||||||
|
/// Cultist pays for its fire with more. SEMan.OnDamaged runs in Character.RPC_Damage on the
|
||||||
|
/// owner's machine, ahead of armor and the health loss, so the scale reaches every hit,
|
||||||
|
/// whoever's machine the attacker is on.
|
||||||
|
/// </summary>
|
||||||
|
public class SE_FenrirFormBuff : SE_Stats
|
||||||
|
{
|
||||||
|
public float m_damageTakenFactor = 1f;
|
||||||
|
|
||||||
|
public override void OnDamaged(HitData hit, Character attacker)
|
||||||
|
{
|
||||||
|
base.OnDamaged(hit, attacker);
|
||||||
|
if (!Mathf.Approximately(m_damageTakenFactor, 1f)) hit.ApplyModifier(m_damageTakenFactor);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public class SE_FenrirCurse : SE_Stats
|
public class SE_FenrirCurse : SE_Stats
|
||||||
{
|
{
|
||||||
public override void Setup(Character character)
|
public override void Setup(Character character)
|
||||||
|
|
|
||||||
167
JotunnModStub/FormLightFollow.cs
Normal file
|
|
@ -0,0 +1,167 @@
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using HarmonyLib;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace RacesOfValheim
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The lights a player wears - the Dvergr circlet's headlamp, a torch in hand - follow the form
|
||||||
|
/// the player has taken.
|
||||||
|
///
|
||||||
|
/// A form hides the human body and leaves it standing where it was: PlayerVisualHider turns its
|
||||||
|
/// renderers off, the Muspell shrinks the Visual to nothing. Either way the gear stays on the
|
||||||
|
/// body's bones, and a Light is not a renderer, so the headlamp kept shining from the hidden
|
||||||
|
/// human's head: at a person's height inside a troll's chest, from the feet of a Muspell. A
|
||||||
|
/// tester saw it stuck where the head had been before the transformation.
|
||||||
|
///
|
||||||
|
/// While the body is hidden, every Light under it is put at the form's head bone, a little in
|
||||||
|
/// front of it. A form with no bone called "head" gets the top front of its own model instead,
|
||||||
|
/// and with no form model at all the light sits centre-forward at a person's head height. The
|
||||||
|
/// lights go back to their own places the moment the body shows again.
|
||||||
|
///
|
||||||
|
/// Run for every player, not only the local one: the headlamp lights the world for onlookers too.
|
||||||
|
/// </summary>
|
||||||
|
public class FormLightFollow : MonoBehaviour
|
||||||
|
{
|
||||||
|
// Lights and the form's head are looked up again this often: VisEquipment rebuilds gear,
|
||||||
|
// and a form can be built a frame after the body is hidden.
|
||||||
|
private const float RescanInterval = 0.25f;
|
||||||
|
|
||||||
|
// RaceEyeHeight's reading of a Visual this small: hidden, not small.
|
||||||
|
private const float HiddenScale = 0.05f;
|
||||||
|
|
||||||
|
// Ahead of the head bone, so the lamp does not light the skull from inside.
|
||||||
|
private const float AheadOfHead = 0.3f;
|
||||||
|
|
||||||
|
// No form model at all: centre-forward, where a person's headlamp would be.
|
||||||
|
private static readonly Vector3 FallbackOffset = new Vector3(0f, 1.6f, 0.4f);
|
||||||
|
|
||||||
|
private static readonly AccessTools.FieldRef<Character, GameObject> VisualRef =
|
||||||
|
AccessTools.FieldRefAccess<Character, GameObject>("m_visual");
|
||||||
|
|
||||||
|
// Each light moved, with the local position it goes back to.
|
||||||
|
private readonly Dictionary<Light, Vector3> moved = new Dictionary<Light, Vector3>();
|
||||||
|
private readonly List<Light> dead = new List<Light>();
|
||||||
|
private float nextScan;
|
||||||
|
private Transform head;
|
||||||
|
private Vector3 anchorOffset = FallbackOffset; // player-local, used when there is no head
|
||||||
|
|
||||||
|
public static void Tick(Player player)
|
||||||
|
{
|
||||||
|
GameObject visual = VisualRef(player);
|
||||||
|
if (visual == null) return;
|
||||||
|
|
||||||
|
bool hidden = PlayerVisualHider.IsHidden(visual.transform) || visual.transform.localScale.y < HiddenScale;
|
||||||
|
FormLightFollow follow = visual.GetComponent<FormLightFollow>();
|
||||||
|
|
||||||
|
if (!hidden)
|
||||||
|
{
|
||||||
|
if (follow != null && follow.moved.Count > 0) follow.Restore();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (follow == null) follow = visual.AddComponent<FormLightFollow>();
|
||||||
|
follow.Follow(player);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Follow(Player player)
|
||||||
|
{
|
||||||
|
if (Time.time >= nextScan)
|
||||||
|
{
|
||||||
|
nextScan = Time.time + RescanInterval;
|
||||||
|
Scan(player);
|
||||||
|
}
|
||||||
|
|
||||||
|
Transform body = player.transform;
|
||||||
|
Vector3 anchor = head != null
|
||||||
|
? head.position + body.forward * AheadOfHead
|
||||||
|
: body.TransformPoint(anchorOffset);
|
||||||
|
|
||||||
|
foreach (Light light in moved.Keys)
|
||||||
|
{
|
||||||
|
if (light != null) light.transform.position = anchor;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Scan(Player player)
|
||||||
|
{
|
||||||
|
dead.Clear();
|
||||||
|
foreach (Light light in moved.Keys)
|
||||||
|
{
|
||||||
|
if (light == null) dead.Add(light);
|
||||||
|
}
|
||||||
|
foreach (Light light in dead) moved.Remove(light);
|
||||||
|
|
||||||
|
foreach (Light light in GetComponentsInChildren<Light>(true))
|
||||||
|
{
|
||||||
|
if (!moved.ContainsKey(light)) moved.Add(light, light.transform.localPosition);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (moved.Count == 0) return;
|
||||||
|
if (head == null || !head.gameObject.activeInHierarchy) FindForm(player);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The form's model is a child of the player beside the Visual (every form builds it that
|
||||||
|
/// way). Its head bone, if it has one; otherwise the top front of its renderers.
|
||||||
|
/// </summary>
|
||||||
|
private void FindForm(Player player)
|
||||||
|
{
|
||||||
|
head = null;
|
||||||
|
anchorOffset = FallbackOffset;
|
||||||
|
|
||||||
|
Transform body = player.transform;
|
||||||
|
foreach (Transform child in body)
|
||||||
|
{
|
||||||
|
if (child == transform || !child.gameObject.activeInHierarchy) continue;
|
||||||
|
if (child.GetComponentInChildren<Animator>() == null) continue;
|
||||||
|
|
||||||
|
head = FindHead(child);
|
||||||
|
if (head != null) return;
|
||||||
|
|
||||||
|
Bounds bounds = default;
|
||||||
|
bool any = false;
|
||||||
|
foreach (Renderer r in child.GetComponentsInChildren<Renderer>())
|
||||||
|
{
|
||||||
|
if (!(r is SkinnedMeshRenderer) && !(r is MeshRenderer)) continue;
|
||||||
|
if (any) bounds.Encapsulate(r.bounds); else { bounds = r.bounds; any = true; }
|
||||||
|
}
|
||||||
|
if (!any) continue;
|
||||||
|
|
||||||
|
Vector3 local = body.InverseTransformPoint(bounds.center);
|
||||||
|
Vector3 size = body.InverseTransformVector(bounds.extents);
|
||||||
|
anchorOffset = new Vector3(local.x, local.y + Mathf.Abs(size.y) * 0.6f, local.z + Mathf.Abs(size.z) * 0.6f);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Transform FindHead(Transform root)
|
||||||
|
{
|
||||||
|
foreach (Transform t in root.GetComponentsInChildren<Transform>())
|
||||||
|
{
|
||||||
|
if (string.Equals(t.name, "head", System.StringComparison.OrdinalIgnoreCase)) return t;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Restore()
|
||||||
|
{
|
||||||
|
foreach (KeyValuePair<Light, Vector3> entry in moved)
|
||||||
|
{
|
||||||
|
if (entry.Key != null) entry.Key.transform.localPosition = entry.Value;
|
||||||
|
}
|
||||||
|
moved.Clear();
|
||||||
|
head = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>LateUpdate, so the form's Animator has already posed the head this frame.</summary>
|
||||||
|
[HarmonyPatch(typeof(Player), "LateUpdate")]
|
||||||
|
public static class Player_LateUpdate_FormLightFollow_Patch
|
||||||
|
{
|
||||||
|
public static void Postfix(Player __instance)
|
||||||
|
{
|
||||||
|
Tick(__instance);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
95
JotunnModStub/FormStagger.cs
Normal file
|
|
@ -0,0 +1,95 @@
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using HarmonyLib;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace RacesOfValheim
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// A staggered player in a form plays the form's own stagger.
|
||||||
|
///
|
||||||
|
/// Vanilla staggers a character with SetTrigger("stagger") on its own Animator (Character.RPC_Stagger),
|
||||||
|
/// and that Animator belongs to the hidden human. The form's Animator never heard of it, so the
|
||||||
|
/// True Form troll stood idle while the player could not move. A tester saw it.
|
||||||
|
///
|
||||||
|
/// Every creature worn as a form has the vanilla stagger ready to play (read offline with
|
||||||
|
/// scripts/dump_controller.py, bundle c4210710): a "stagger" trigger and an AnyState -> Stagger
|
||||||
|
/// transition in troll_animator, fenring_animator, fenring_cultist_animator, wolf_animator,
|
||||||
|
/// ulv_animator, SeekerBrute_animator (the Sverm Ravager) and bat_animator (the Aswid bat).
|
||||||
|
/// gd_king_animator (the Muspell) and hatchling_animator (the Skadi drake) have none, and are
|
||||||
|
/// left alone by the parameter check.
|
||||||
|
///
|
||||||
|
/// The cue is Character.IsStaggering(), which reads the player's Animator state. The player's
|
||||||
|
/// triggers are replicated, so this holds for onlookers' copies of the form too, with nothing
|
||||||
|
/// published of its own. Fired once, as the stagger starts.
|
||||||
|
///
|
||||||
|
/// A stagger also cancels the local form's attack, as it cancels a weapon's in vanilla. The
|
||||||
|
/// form's swing waits for its clip's hit event and lands on a timeout if none comes, so a
|
||||||
|
/// stagger that cut the clip short still dealt the blow 1.5 s later. MarkAttack is called as an
|
||||||
|
/// attack starts, and AttackInterrupted tells the hit whether a stagger began since.
|
||||||
|
/// </summary>
|
||||||
|
internal static class FormStagger
|
||||||
|
{
|
||||||
|
private const string Trigger = "stagger";
|
||||||
|
|
||||||
|
private static readonly AccessTools.FieldRef<Character, Animator> AnimatorRef =
|
||||||
|
AccessTools.FieldRefAccess<Character, Animator>("m_animator");
|
||||||
|
|
||||||
|
private static readonly HashSet<int> staggering = new HashSet<int>();
|
||||||
|
private static readonly List<Animator> animators = new List<Animator>();
|
||||||
|
|
||||||
|
// Staggers of the local player so far, and the count when the current attack started.
|
||||||
|
private static int localStaggers;
|
||||||
|
private static int attackMark;
|
||||||
|
|
||||||
|
public static void MarkAttack() => attackMark = localStaggers;
|
||||||
|
|
||||||
|
/// <summary>True if the local player has been staggered since the last MarkAttack.</summary>
|
||||||
|
public static bool AttackInterrupted => localStaggers != attackMark;
|
||||||
|
|
||||||
|
public static void Tick(Player player)
|
||||||
|
{
|
||||||
|
int id = player.GetInstanceID();
|
||||||
|
if (!player.IsStaggering())
|
||||||
|
{
|
||||||
|
staggering.Remove(id);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!staggering.Add(id)) return;
|
||||||
|
if (player == Player.m_localPlayer) localStaggers++;
|
||||||
|
|
||||||
|
Animator own = AnimatorRef(player);
|
||||||
|
RuntimeAnimatorController ownController = own != null ? own.runtimeAnimatorController : null;
|
||||||
|
|
||||||
|
player.GetComponentsInChildren(false, animators);
|
||||||
|
foreach (Animator anim in animators)
|
||||||
|
{
|
||||||
|
// The human's own Animator staggers already, and so does anything driven by a copy of
|
||||||
|
// its controller (a VRM model).
|
||||||
|
if (anim == own || anim.runtimeAnimatorController == null) continue;
|
||||||
|
if (anim.runtimeAnimatorController == ownController) continue;
|
||||||
|
if (!anim.isActiveAndEnabled || !HasTrigger(anim)) continue;
|
||||||
|
|
||||||
|
anim.SetTrigger(Trigger);
|
||||||
|
}
|
||||||
|
animators.Clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static bool HasTrigger(Animator anim)
|
||||||
|
{
|
||||||
|
foreach (AnimatorControllerParameter p in anim.parameters)
|
||||||
|
{
|
||||||
|
if (p.type == AnimatorControllerParameterType.Trigger && p.name == Trigger) return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
[HarmonyPatch(typeof(Player), "LateUpdate")]
|
||||||
|
public static class Player_LateUpdate_FormStagger_Patch
|
||||||
|
{
|
||||||
|
public static void Postfix(Player __instance)
|
||||||
|
{
|
||||||
|
FormStagger.Tick(__instance);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
92
JotunnModStub/HunterSenses.cs
Normal file
|
|
@ -0,0 +1,92 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace RacesOfValheim
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The hunter's senses the Aswid and the Fenrir share: every untamed creature within a radius
|
||||||
|
/// gets a green light, seen only by the local player. The Aswid has it as a passive from Moder,
|
||||||
|
/// the Fenrir in any of its four forms.
|
||||||
|
///
|
||||||
|
/// The lights are local GameObjects parented to the creature, so nothing goes on the network.
|
||||||
|
/// The light's range and strength are the Aswid's settings; each race brings its own radius.
|
||||||
|
/// </summary>
|
||||||
|
public static class HunterSenses
|
||||||
|
{
|
||||||
|
private static readonly Dictionary<Character, GameObject> lights = new Dictionary<Character, GameObject>();
|
||||||
|
private static float timer;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Called every frame while the senses are on. Sweeps once per refresh interval;
|
||||||
|
/// onSensed runs for each creature in range (the Aswid marks them with its status effect).
|
||||||
|
/// </summary>
|
||||||
|
public static void Tick(float radius, Action<Character> onSensed = null)
|
||||||
|
{
|
||||||
|
Player player = Player.m_localPlayer;
|
||||||
|
if (player == null) return;
|
||||||
|
|
||||||
|
timer -= Time.deltaTime;
|
||||||
|
if (timer > 0f) return;
|
||||||
|
timer = AswidConfig.SensesRefreshInterval.Value;
|
||||||
|
|
||||||
|
Vector3 myPos = player.transform.position;
|
||||||
|
HashSet<Character> inRange = new HashSet<Character>();
|
||||||
|
|
||||||
|
foreach (Character c in Character.GetAllCharacters())
|
||||||
|
{
|
||||||
|
if (c == null || c == player || c.IsDead() || c.IsTamed()) continue;
|
||||||
|
if (Vector3.Distance(c.transform.position, myPos) > radius) continue;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
inRange.Add(c);
|
||||||
|
onSensed?.Invoke(c);
|
||||||
|
|
||||||
|
if (!lights.ContainsKey(c))
|
||||||
|
{
|
||||||
|
GameObject lightObj = new GameObject("AswidSensesLight");
|
||||||
|
lightObj.transform.SetParent(c.transform);
|
||||||
|
lightObj.transform.position = c.GetCenterPoint();
|
||||||
|
|
||||||
|
Light pLight = lightObj.AddComponent<Light>();
|
||||||
|
pLight.type = LightType.Point;
|
||||||
|
pLight.color = Color.green;
|
||||||
|
pLight.range = AswidConfig.SensesLightRange.Value;
|
||||||
|
pLight.intensity = AswidConfig.SensesLightIntensity.Value;
|
||||||
|
pLight.shadows = LightShadows.None;
|
||||||
|
|
||||||
|
lights[c] = lightObj;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Jotunn.Logger.LogError($"[Senses] Error processing mob {c.name}: {ex}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
List<Character> keysToRemove = new List<Character>();
|
||||||
|
foreach (var kvp in lights)
|
||||||
|
{
|
||||||
|
if (kvp.Key == null || kvp.Key.IsDead() || !inRange.Contains(kvp.Key))
|
||||||
|
{
|
||||||
|
if (kvp.Value != null) UnityEngine.Object.Destroy(kvp.Value);
|
||||||
|
keysToRemove.Add(kvp.Key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
foreach (var k in keysToRemove) lights.Remove(k);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>Puts every light out, for when the senses end (a form reverts, a tier is lost).</summary>
|
||||||
|
public static void Clear()
|
||||||
|
{
|
||||||
|
if (lights.Count == 0) return;
|
||||||
|
foreach (var kvp in lights)
|
||||||
|
{
|
||||||
|
if (kvp.Value != null) UnityEngine.Object.Destroy(kvp.Value);
|
||||||
|
}
|
||||||
|
lights.Clear();
|
||||||
|
timer = 0f;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -36,10 +36,13 @@ namespace RacesOfValheim
|
||||||
/// <paramref name="localPosition"/> is where the model's BOTTOM CENTRE goes.
|
/// <paramref name="localPosition"/> is where the model's BOTTOM CENTRE goes.
|
||||||
/// <paramref name="targetSize"/> is how big its largest dimension should end up, in metres,
|
/// <paramref name="targetSize"/> is how big its largest dimension should end up, in metres,
|
||||||
/// measured AFTER <paramref name="localRotation"/> has been applied.
|
/// measured AFTER <paramref name="localRotation"/> has been applied.
|
||||||
|
/// <paramref name="activeOnly"/> drops every child the source keeps switched off before measuring.
|
||||||
|
/// A build piece carries its snow cover, its fire, its worn and broken meshes that way, and they
|
||||||
|
/// count towards the size: the cauldron's hidden tripod legs are two metres long.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static GameObject Attach(Transform parent, string holderName, string sourcePrefab,
|
public static GameObject Attach(Transform parent, string holderName, string sourcePrefab,
|
||||||
Vector3 localPosition, Quaternion localRotation, float targetSize,
|
Vector3 localPosition, Quaternion localRotation, float targetSize,
|
||||||
string label)
|
string label, bool activeOnly = false)
|
||||||
{
|
{
|
||||||
GameObject source = Jotunn.Managers.PrefabManager.Cache.GetPrefab<GameObject>(sourcePrefab);
|
GameObject source = Jotunn.Managers.PrefabManager.Cache.GetPrefab<GameObject>(sourcePrefab);
|
||||||
if (source == null)
|
if (source == null)
|
||||||
|
|
@ -52,7 +55,7 @@ namespace RacesOfValheim
|
||||||
return empty;
|
return empty;
|
||||||
}
|
}
|
||||||
|
|
||||||
return Attach(parent, holderName, source, localPosition, localRotation, targetSize, label);
|
return Attach(parent, holderName, source, localPosition, localRotation, targetSize, label, activeOnly);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -66,7 +69,7 @@ namespace RacesOfValheim
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static GameObject Attach(Transform parent, string holderName, GameObject source,
|
public static GameObject Attach(Transform parent, string holderName, GameObject source,
|
||||||
Vector3 localPosition, Quaternion localRotation, float targetSize,
|
Vector3 localPosition, Quaternion localRotation, float targetSize,
|
||||||
string label)
|
string label, bool activeOnly = false)
|
||||||
{
|
{
|
||||||
GameObject holder = new GameObject(holderName);
|
GameObject holder = new GameObject(holderName);
|
||||||
holder.transform.SetParent(parent, false);
|
holder.transform.SetParent(parent, false);
|
||||||
|
|
@ -110,6 +113,16 @@ namespace RacesOfValheim
|
||||||
if (nview != null) Object.DestroyImmediate(nview);
|
if (nview != null) Object.DestroyImmediate(nview);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (activeOnly)
|
||||||
|
{
|
||||||
|
foreach (Transform child in copy.GetComponentsInChildren<Transform>(true))
|
||||||
|
{
|
||||||
|
// Null once an inactive parent above it has already gone.
|
||||||
|
if (child == null || child == copy.transform || child.gameObject.activeSelf) continue;
|
||||||
|
Object.DestroyImmediate(child.gameObject);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
FitAndGround(copy.transform, holder.transform, targetSize, sourcePrefab, label);
|
FitAndGround(copy.transform, holder.transform, targetSize, sourcePrefab, label);
|
||||||
|
|
||||||
holder.SetActive(true);
|
holder.SetActive(true);
|
||||||
|
|
|
||||||
|
|
@ -1,113 +0,0 @@
|
||||||
# RacesOfValheim
|
|
||||||
|
|
||||||
A comprehensive Valheim mod that allows you to play as different unique races, each offering distinct mechanics, visual transformations, and a deep progression system tailored to your journey in Valheim.
|
|
||||||
|
|
||||||
## Features
|
|
||||||
|
|
||||||
This mod currently introduces 4 custom races:
|
|
||||||
|
|
||||||
### 1. Skeleton
|
|
||||||
- **Stamina-less Combat**: Skeletons do not consume stamina and do not use the stamina bar.
|
|
||||||
- **Undead Diet**: You cannot eat standard food. Instead, you gain maximum health automatically as you defeat Valheim's bosses to compensate for the lack of food buffs.
|
|
||||||
### 2. Skadi
|
|
||||||
- **Ice Affinity**: Gain unique resistance and affinity to the cold.
|
|
||||||
|
|
||||||
### 3. Fenrir
|
|
||||||
- **Beast Form**: Transform into a powerful wolf-like beast.
|
|
||||||
- **Cultist Form**: Transform into a Cultist to wield fire abilities.
|
|
||||||
- **Progression**: The beast and cultist forms evolve as you defeat Valheim's bosses, granting new abilities, cooldown reductions, and power scaling. Immune to fall damage in both forms.
|
|
||||||
|
|
||||||
### 4. Aswid
|
|
||||||
- **The Vampire**: A creature of the night with powerful life-draining abilities.
|
|
||||||
- **Bat Transformation**: Press `G` to transform into a bat, allowing you to fly over obstacles and travel quickly.
|
|
||||||
- **Blood Magic**: Block to channel a life-draining aura that saps the life of enemies in an area around you (doubled radius at night).
|
|
||||||
- **Blood Magic Mastery**: You can cast Blood Magic items with infinite Eitr, relying purely on their health costs.
|
|
||||||
- **Night Prowler**: Your passive speed and jump bonuses double during the night.
|
|
||||||
- **Undead Vigor**: Like the skeleton, the Aswid has infinite stamina. You consume the lifeforce of fallen foes directly instead of eating standard food.
|
|
||||||
|
|
||||||
## Installation (manual)
|
|
||||||
1. Install BepInExPack Valheim.
|
|
||||||
2. Install Jotunn.
|
|
||||||
3. Extract the contents of this mod into your `BepInEx/plugins` folder.
|
|
||||||
|
|
||||||
## Changelog
|
|
||||||
**v1.0.0**
|
|
||||||
- Initial release with 4 distinct races.
|
|
||||||
- Added Aswid life-draining and night transformations.
|
|
||||||
- Complete progression system tied to Valheim's bosses.
|
|
||||||
|
|
||||||
**v1.1.0**
|
|
||||||
- **Aswid**: Passive abilities (Speed and Jump) are now properly doubled during the night.
|
|
||||||
- **Aswid**: New Enslavement Power (Yagluth tier)! Press E on non-tameable, non-boss enemies to enslave them for 60 seconds (15-min cooldown). Enslaved thralls fight alongside you and drop standard loot.
|
|
||||||
- **Aswid**: Edible thralls are automatically consumed upon death, granting you their lifeforce (Fader tier).
|
|
||||||
- **Aswid**: Complete overhaul of the Food system. Added Mistlands and Ashlands creatures to the consumption map. Accurately scaled food stats based on creature health.
|
|
||||||
- **Aswid**: Excluded undead and inorganic creatures (Skeletons, Draugrs, Golems, etc.) from being edible.
|
|
||||||
- **Aswid**: Added a dynamic green light effect to all forms (Bonemass tier).
|
|
||||||
|
|
||||||
**v1.2.0**
|
|
||||||
- **Multiplayer Sync**: Fully implemented visual syncing for Aswid forms (Bat, Mist) and Skadi forms (Bear, Wolf, Hatchling, Fader) so other players can see your transformations in multiplayer!
|
|
||||||
- **Aswid**: Scrapped the Fader (Surtling) visual override; reaching the final progression state now makes the player 10% taller and adds a flat +30 physical damage bonus.
|
|
||||||
- **Aswid**: Defeating enemies with physical attacks in the final state now automatically consumes them if you have food slots available.
|
|
||||||
- **General**: Eradicated remaining localizations of the old "Strigoi" name.
|
|
||||||
|
|
||||||
**v1.3.0**
|
|
||||||
- **Progression Fix**: Fixed a massive bug where boss progression states were misaligned. Players no longer receive Eikthyr or higher-tier powers immediately upon starting a new game (State 1). All unlocks now perfectly match the corresponding boss defeat global keys.
|
|
||||||
- **Furling**: Fine-tuned the custom 3D Goblin Head trophy alignment and scaling. It now fits perfectly inside the player's skull, revealing only the goblin ears!
|
|
||||||
- **Documentation**: Added complete level-by-level progression lists to the README for all races.
|
|
||||||
|
|
||||||
**v1.3.2**
|
|
||||||
- **Aswid**: Refined the Aswid's diet. Excluded undead/inorganic Ashlands creatures (Charred, Morgen).
|
|
||||||
- **Aswid**: Added a 4th stomach slot exclusively for Aswid prey!
|
|
||||||
- **Aswid**: Added a keybind (I) to toggle the automatic devour on/off.
|
|
||||||
|
|
||||||
**v1.3.3**
|
|
||||||
- **Aswid**: Fixed a bug where devouring a mob would fail if the player was still in an attack or movement animation.
|
|
||||||
- **Aswid**: Added a passive lifesteal scaling mechanic! You now heal for 2% of the physical damage dealt per boss defeated (up to 14% at endgame). This amount is doubled during the night!
|
|
||||||
|
|
||||||
## Race Progressions (Level-by-Level)
|
|
||||||
|
|
||||||
### Aswid Progression
|
|
||||||
- **Base (No Bosses)**: Vampiric Aura (heal 20% on magic AoE damage). Progressive stats (+3 Armor, +5 Damage, +3% Speed, +3% Jump per boss killed). All passive bonuses are doubled at night! You can cast Blood Magic items with infinite Eitr.
|
|
||||||
- **Eikthyr**: Bat Transformation (Night only).
|
|
||||||
- **The Elder**: Bat Transformation (Always active).
|
|
||||||
- **Bonemass**: Superhuman Senses (Aura reveals untamed creatures).
|
|
||||||
- **Moder**: Freezing Blood (Permanent immunity to Freezing and Poison).
|
|
||||||
- **Yagluth**: Enslavement Power (E Key - Enslave non-tameable enemies).
|
|
||||||
- **The Queen**: Mist Form (H Key - Immune to physical/poison, double aura damage, weak to fire/frost/spirit. Breaks at sunrise).
|
|
||||||
- **Fader**: +10% Size, +30 Physical Damage. Physical kills automatically consume enemies.
|
|
||||||
|
|
||||||
### Skadi Progression
|
|
||||||
- **Base (No Bosses)**: Immune to Cold, Bonus Frost Damage, 50% Frost Resistance.
|
|
||||||
- **Eikthyr**: +20% Eitr Regen, Freezing to Cold (mountains act as normal cold), Cold Spell.
|
|
||||||
- **The Elder**: Drake Form (Cannot attack).
|
|
||||||
- **Bonemass**: Drake Form (Can attack).
|
|
||||||
- **Moder**: Moder Form (1 min duration, 10 min cooldown).
|
|
||||||
- **Yagluth**: Improved Cold Spell. Moder Form (1 min duration, 5 min cooldown).
|
|
||||||
- **The Queen**: Moder Form (Unlimited duration, no cooldown).
|
|
||||||
- **Fader**: Skeleton Dragon Form.
|
|
||||||
|
|
||||||
### Skeleton Progression
|
|
||||||
- **Base (No Bosses)**: +50 Max Health. Undead Diet (Cannot eat mortal food, no stamina bar).
|
|
||||||
- **Eikthyr**: Poison Skeleton Model, Poison Immunity, 5% Lifesteal, +80 Max Health.
|
|
||||||
- **The Elder**: 10% Lifesteal, Auto-Stun on First Hit, +110 Max Health.
|
|
||||||
- **Bonemass**: 15% Lifesteal, Poison Attacks, +140 Max Health.
|
|
||||||
- **Moder**: Fire Skeleton Model, 20% Lifesteal, Fire Aura, Enhanced Regen, +170 Max Health.
|
|
||||||
- **Yagluth**: 25% Lifesteal, Auto Resurrect, +200 Max Health.
|
|
||||||
- **The Queen**: 30% Lifesteal, Summon on Kill (Max 3 Skeletons), +230 Max Health.
|
|
||||||
- **Fader**: 35% Lifesteal, Max 5 Summons, +275 Max Health.
|
|
||||||
|
|
||||||
### Fenrir Progression
|
|
||||||
- **Base (No Bosses)**: Progressive stats (+3 Armor, +5 Damage, -10% Fall Damage, +3% Speed, +3% Jump per boss killed).
|
|
||||||
- **The Elder**: Wolf Form (Night).
|
|
||||||
- **Bonemass**: Wolf Form (Day/Night). Ulv Form (Night).
|
|
||||||
- **Moder**: Ulv Form (Day/Night). Fenring Form (Night).
|
|
||||||
- **Yagluth**: Cultist Form (Night - 1 min duration, 10 min cooldown).
|
|
||||||
- **The Queen**: Fenring Form (Day/Night). Cultist Form (Night - 1 min duration, 5 min cooldown).
|
|
||||||
- **Fader**: Cultist Form (Day/Night).
|
|
||||||
|
|
||||||
### Furling Progression
|
|
||||||
- **Eikthyr**: Master of Shadows (Bonus attack damage when in the dark or at night).
|
|
||||||
- **The Elder**: The Wickerman (-50% Fire and Poison damage, increased to -90% if it's from an arrow).
|
|
||||||
- **Bonemass**: Dance of the Dead (Ignore certain crafting costs).
|
|
||||||
- **Moder**: The Man/Woman on the Silver Mountain (Doubles normal enemy trophy drops, yields gold coins based on stars within 25 meters, and doubles mined raw ore yield).
|
|
||||||
- **Yagluth**: The King is Dead, Hail to the King/Queen (In the Plains biome, the 2x XP multiplier is extended to all non-combat skills).
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
{
|
{
|
||||||
"name": "RacesOfValheim",
|
"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.",
|
"description": "A Valheim mod that adds eleven custom playable races (Alfar, 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.6.0",
|
"version_number": "1.6.11",
|
||||||
"website_url": "",
|
"website_url": "",
|
||||||
"dependencies": [
|
"dependencies": [
|
||||||
"denikson-BepInExPack_Valheim-5.4.2333",
|
"denikson-BepInExPack_Valheim-5.4.2333",
|
||||||
|
|
|
||||||
197
JotunnModStub/PieceLook.cs
Normal file
|
|
@ -0,0 +1,197 @@
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace RacesOfValheim
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Recolouring a cloned vanilla piece without touching the original.
|
||||||
|
///
|
||||||
|
/// A clone made by CreateClonedPrefab shares its MATERIALS with the vanilla prefab, so writing a
|
||||||
|
/// colour onto renderer.sharedMaterial would repaint every Ward or cartography table in the world.
|
||||||
|
/// Each material is copied once and the copy is written; renderers that shared one material before
|
||||||
|
/// share the one copy after, so the LOD, worn and broken meshes stay matched.
|
||||||
|
/// </summary>
|
||||||
|
public static class PieceLook
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Multiplies the base colour of every mesh under <paramref name="root"/>, inactive ones included
|
||||||
|
/// (a piece's worn and broken meshes are switched off until it takes damage). Particles are left
|
||||||
|
/// alone: that is what <see cref="Rehue"/> is for.
|
||||||
|
/// </summary>
|
||||||
|
public static void Tint(Transform root, Color tint)
|
||||||
|
{
|
||||||
|
if (root == null) return;
|
||||||
|
|
||||||
|
var copies = new Dictionary<Material, Material>();
|
||||||
|
foreach (Renderer renderer in root.GetComponentsInChildren<Renderer>(true))
|
||||||
|
{
|
||||||
|
if (renderer == null || renderer is ParticleSystemRenderer) continue;
|
||||||
|
|
||||||
|
Material[] materials = renderer.sharedMaterials;
|
||||||
|
for (int i = 0; i < materials.Length; i++)
|
||||||
|
{
|
||||||
|
Material copy = CopyOf(materials[i], copies);
|
||||||
|
if (copy == null) continue;
|
||||||
|
if (copy.HasProperty("_Color")) copy.SetColor("_Color", copy.GetColor("_Color") * tint);
|
||||||
|
materials[i] = copy;
|
||||||
|
}
|
||||||
|
renderer.sharedMaterials = materials;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Swaps the hue of everything under <paramref name="root"/> that GLOWS - lights, particles and
|
||||||
|
/// any material with emission - for <paramref name="glow"/>, keeping each one's brightness.
|
||||||
|
///
|
||||||
|
/// Brightness is kept rather than overwritten because these values are not 0 to 1: the Ward's
|
||||||
|
/// sparks are authored at a colour of 2.0, and painting them a flat 1.0 blue would dim them by
|
||||||
|
/// half. A material whose emission is black does not glow and is skipped, so the Ward's stone
|
||||||
|
/// stays stone.
|
||||||
|
/// </summary>
|
||||||
|
public static void Rehue(Transform root, Color glow)
|
||||||
|
{
|
||||||
|
if (root == null) return;
|
||||||
|
|
||||||
|
foreach (Light light in root.GetComponentsInChildren<Light>(true))
|
||||||
|
{
|
||||||
|
if (light != null) light.color = glow;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (ParticleSystem ps in root.GetComponentsInChildren<ParticleSystem>(true))
|
||||||
|
{
|
||||||
|
if (ps == null) continue;
|
||||||
|
ParticleSystem.MainModule main = ps.main;
|
||||||
|
main.startColor = new ParticleSystem.MinMaxGradient(glow);
|
||||||
|
}
|
||||||
|
|
||||||
|
var copies = new Dictionary<Material, Material>();
|
||||||
|
foreach (Renderer renderer in root.GetComponentsInChildren<Renderer>(true))
|
||||||
|
{
|
||||||
|
if (renderer == null) continue;
|
||||||
|
bool particles = renderer is ParticleSystemRenderer;
|
||||||
|
|
||||||
|
Material[] materials = renderer.sharedMaterials;
|
||||||
|
bool changed = false;
|
||||||
|
for (int i = 0; i < materials.Length; i++)
|
||||||
|
{
|
||||||
|
Material source = materials[i];
|
||||||
|
if (source == null) continue;
|
||||||
|
|
||||||
|
bool emits = source.HasProperty("_EmissionColor") && Brightness(source.GetColor("_EmissionColor")) > 0.01f;
|
||||||
|
if (!emits && !particles) continue;
|
||||||
|
|
||||||
|
Material copy = CopyOf(source, copies);
|
||||||
|
if (emits) Recolour(copy, "_EmissionColor", glow);
|
||||||
|
if (particles)
|
||||||
|
{
|
||||||
|
Recolour(copy, "_Color", glow);
|
||||||
|
Recolour(copy, "_TintColor", glow);
|
||||||
|
}
|
||||||
|
materials[i] = copy;
|
||||||
|
changed = true;
|
||||||
|
}
|
||||||
|
if (changed) renderer.sharedMaterials = materials;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Swaps textures by the name of the texture they replace: every material under
|
||||||
|
/// <paramref name="root"/> that uses "Cartographer_d" gets <paramref name="replacements"/>'s
|
||||||
|
/// "Cartographer_d" instead, whichever slot it sits in. Materials are copied as in Tint.
|
||||||
|
/// </summary>
|
||||||
|
public static void Retexture(Transform root, IDictionary<string, Texture> replacements)
|
||||||
|
{
|
||||||
|
if (root == null) return;
|
||||||
|
|
||||||
|
var copies = new Dictionary<Material, Material>();
|
||||||
|
foreach (Renderer renderer in root.GetComponentsInChildren<Renderer>(true))
|
||||||
|
{
|
||||||
|
if (renderer == null || renderer is ParticleSystemRenderer) continue;
|
||||||
|
|
||||||
|
Material[] materials = renderer.sharedMaterials;
|
||||||
|
bool changed = false;
|
||||||
|
for (int i = 0; i < materials.Length; i++)
|
||||||
|
{
|
||||||
|
Material source = materials[i];
|
||||||
|
if (source == null) continue;
|
||||||
|
|
||||||
|
foreach (string property in source.GetTexturePropertyNames())
|
||||||
|
{
|
||||||
|
Texture current = source.GetTexture(property);
|
||||||
|
if (current == null || !replacements.TryGetValue(current.name, out Texture replacement)) continue;
|
||||||
|
|
||||||
|
Material copy = CopyOf(source, copies);
|
||||||
|
copy.SetTexture(property, replacement);
|
||||||
|
materials[i] = copy;
|
||||||
|
changed = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (changed) renderer.sharedMaterials = materials;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// ImageConversion.LoadImage, found at run time. Its module is built against netstandard 2.1 and
|
||||||
|
/// this project targets net48, so referencing it at compile time fails the build (CS1705); the
|
||||||
|
/// game has the module loaded either way.
|
||||||
|
/// </summary>
|
||||||
|
private static readonly System.Reflection.MethodInfo LoadImage =
|
||||||
|
System.Type.GetType("UnityEngine.ImageConversion, UnityEngine.ImageConversionModule")
|
||||||
|
?.GetMethod("LoadImage", new[] { typeof(Texture2D), typeof(byte[]), typeof(bool) });
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// A PNG embedded in the DLL (see the csproj's EmbeddedResource), or null with a warning.
|
||||||
|
/// <paramref name="linear"/> for anything that is data rather than colour - a normal map read
|
||||||
|
/// as sRGB comes out bent.
|
||||||
|
/// </summary>
|
||||||
|
public static Texture2D LoadTexture(string resource, bool linear = false)
|
||||||
|
{
|
||||||
|
using (System.IO.Stream stream = typeof(PieceLook).Assembly.GetManifestResourceStream(resource))
|
||||||
|
{
|
||||||
|
if (stream == null)
|
||||||
|
{
|
||||||
|
Jotunn.Logger.LogWarning($"No embedded texture '{resource}'.");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
byte[] bytes = new byte[stream.Length];
|
||||||
|
int read = 0;
|
||||||
|
while (read < bytes.Length) read += stream.Read(bytes, read, bytes.Length - read);
|
||||||
|
|
||||||
|
Texture2D texture = new Texture2D(2, 2, TextureFormat.RGBA32, true, linear)
|
||||||
|
{
|
||||||
|
name = System.IO.Path.GetFileNameWithoutExtension(resource),
|
||||||
|
anisoLevel = 4,
|
||||||
|
};
|
||||||
|
if (LoadImage == null || !(bool)LoadImage.Invoke(null, new object[] { texture, bytes, true }))
|
||||||
|
{
|
||||||
|
Jotunn.Logger.LogWarning($"Embedded texture '{resource}' would not decode.");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return texture;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void Recolour(Material material, string property, Color glow)
|
||||||
|
{
|
||||||
|
if (!material.HasProperty(property)) return;
|
||||||
|
Color old = material.GetColor(property);
|
||||||
|
Color hue = glow * Brightness(old);
|
||||||
|
hue.a = old.a;
|
||||||
|
material.SetColor(property, hue);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static float Brightness(Color colour) => Mathf.Max(colour.r, Mathf.Max(colour.g, colour.b));
|
||||||
|
|
||||||
|
private static Material CopyOf(Material source, Dictionary<Material, Material> copies)
|
||||||
|
{
|
||||||
|
if (source == null) return null;
|
||||||
|
if (!copies.TryGetValue(source, out Material copy))
|
||||||
|
{
|
||||||
|
copy = new Material(source) { name = source.name + "_rov" };
|
||||||
|
copies[source] = copy;
|
||||||
|
}
|
||||||
|
return copy;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
51
JotunnModStub/PlayerFace.cs
Normal file
|
|
@ -0,0 +1,51 @@
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace RacesOfValheim
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Where a player's painted eyes are, for the races that hang something over them (Alfar,
|
||||||
|
/// Aswid, Dvergar, Sverm).
|
||||||
|
///
|
||||||
|
/// Every eye constant in this mod (0.081 forward, 0.181 up, 0.032 apart) was tuned on the MALE
|
||||||
|
/// body. The female body is a different mesh on the same rig and the same skin texture, and it
|
||||||
|
/// maps the painted eyes elsewhere: read offline from VisEquipment.m_models (bodymale vs
|
||||||
|
/// bodyfem, Valheim 1.0.20), by finding the dark socket pixels of PlayerCharacter_01 and
|
||||||
|
/// following the UVs back onto each mesh in head-bone space, the female eyes sit about 6mm
|
||||||
|
/// lower and a quarter closer together. Both are weighted 100% to Head, so once placed they
|
||||||
|
/// follow the head exactly; a sphere on the male spot simply sits on the brow, off the face.
|
||||||
|
///
|
||||||
|
/// HEAD-LOCAL UNITS. The player armature is authored at 100x, so one metre at human scale is
|
||||||
|
/// 0.01 in the head bone's own space. That is a constant of the rig, not of this frame:
|
||||||
|
/// reading headBone.lossyScale live instead breaks under a non-uniform body scale (the Alfar),
|
||||||
|
/// where the value drifts as the head turns.
|
||||||
|
/// </summary>
|
||||||
|
public static class PlayerFace
|
||||||
|
{
|
||||||
|
public const float MetresToHeadLocal = 0.01f;
|
||||||
|
|
||||||
|
// Female against male. The UV reading gave -6mm, but in game the eyes still sat a full
|
||||||
|
// eye-height above the painted ones on every race (screenshots, 2026-10-27), so the
|
||||||
|
// height is the measured shift plus that.
|
||||||
|
private const float FemaleHeightShift = -0.014f;
|
||||||
|
private const float FemaleSeparationScale = 0.75f;
|
||||||
|
private const float FemaleSizeScale = 0.9f;
|
||||||
|
|
||||||
|
/// <summary>True while the body wears the female mesh (VisEquipment model index 1).</summary>
|
||||||
|
public static bool IsFemale(Player player)
|
||||||
|
{
|
||||||
|
VisEquipment vis = player != null ? player.GetComponent<VisEquipment>() : null;
|
||||||
|
if (vis == null || vis.m_bodyModel == null || vis.m_models == null || vis.m_models.Length < 2) return false;
|
||||||
|
return vis.m_bodyModel.sharedMesh == vis.m_models[1].m_mesh;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>Moves male-tuned eye numbers (metres) onto the female face; leaves a male face alone.</summary>
|
||||||
|
public static void AdjustEyes(Player player, ref float height, ref float separation, ref float size)
|
||||||
|
{
|
||||||
|
if (!IsFemale(player)) return;
|
||||||
|
|
||||||
|
height += FemaleHeightShift;
|
||||||
|
separation *= FemaleSeparationScale;
|
||||||
|
size *= FemaleSizeScale;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,156 +0,0 @@
|
||||||
# RacesOfValheim
|
|
||||||
|
|
||||||
A comprehensive Valheim mod that allows you to play as different unique races, each offering distinct mechanics, visual transformations, and a deep progression system tailored to your journey in Valheim.
|
|
||||||
|
|
||||||
## Features
|
|
||||||
|
|
||||||
This mod currently introduces 6 custom races:
|
|
||||||
|
|
||||||
### 1. Skeleton
|
|
||||||
- **Stamina-less Combat**: Skeletons do not consume stamina and do not use the stamina bar.
|
|
||||||
- **Undead Diet**: You cannot eat standard food. Instead, you gain maximum health automatically as you defeat Valheim's bosses to compensate for the lack of food buffs.
|
|
||||||
|
|
||||||
### 2. Skadi
|
|
||||||
- **Ice Affinity**: Gain unique resistance and affinity to the cold.
|
|
||||||
- **Drake Form**: Transform into a frost Drake, taking to the skies and attacking from above.
|
|
||||||
- **Dragon Form**: Evolve your form into the mighty Moder and, eventually, unleash the terrifying power of the Skeleton Dragon.
|
|
||||||
|
|
||||||
### 3. Fenrir
|
|
||||||
- **Beast Form**: Transform into a powerful wolf-like beast.
|
|
||||||
- **Cultist Form**: Transform into a Cultist to wield fire abilities.
|
|
||||||
- **Progression**: The beast and cultist forms evolve as you defeat Valheim's bosses, granting new abilities, cooldown reductions, and power scaling. Immune to fall damage in both forms.
|
|
||||||
|
|
||||||
### 4. Aswid
|
|
||||||
- **The Vampire**: A creature of the night with powerful life-draining abilities.
|
|
||||||
- **Bat Transformation**: Press G to transform into a bat, allowing you to fly over obstacles and travel quickly.
|
|
||||||
- **Blood Magic**: Block to channel a life-draining aura that saps the life of enemies in an area around you (doubled radius at night). **Only available while in Bat or Mist form.**
|
|
||||||
- **Blood Magic Mastery**: You can cast Blood Magic items with infinite Eitr, relying purely on their health costs.
|
|
||||||
- **Day walker, Night stalker**: Your passive speed and jump bonuses double during the night.
|
|
||||||
- **Undead Vigor**: Like the skeleton, the Aswid has infinite stamina. You consume the lifeforce of fallen foes directly instead of eating standard food.
|
|
||||||
|
|
||||||
### 5. Furling
|
|
||||||
- **Goblin Heritage**: You play as a Goblin (Fuling). No beard, no hair (for males).
|
|
||||||
- **Combat Mastery**: All weapon and combat skills gain 2x XP permanently.
|
|
||||||
- **Boss-Driven Progression**: Each major boss defeat unlocks a new passive ability.
|
|
||||||
|
|
||||||
### 6. Trol
|
|
||||||
- **Trol Heritage**: Play as a massive Trol! You are natively 20% larger than a human.
|
|
||||||
- **Immense Strength**: Your carry weight is vastly increased and your armor naturally scales as you defeat bosses.
|
|
||||||
- **Rock Throwing**: You can hurl boulders at your enemies for massive physical damage.
|
|
||||||
- **Tree Weaponry**: At higher levels, transform into your True Form to rip logs directly out of trees and wield them as devastating weapons or throw them!
|
|
||||||
|
|
||||||
## Installation (manual)
|
|
||||||
1. Install BepInExPack Valheim.
|
|
||||||
2. Install Jotunn.
|
|
||||||
3. Extract the contents of this mod into your BepInEx/plugins folder.
|
|
||||||
|
|
||||||
## Race Progressions (Level-by-Level)
|
|
||||||
|
|
||||||
### Trol Progression
|
|
||||||
- **Base (No Bosses)**: +20% Size. +200 Max Carry Weight. Gain +3 Armor per boss defeated.
|
|
||||||
- **Eikthyr**: Increased XP gain for physical labor and blunt combat (Clubs, Unarmed, Axes, Pickaxes, WoodCutting).
|
|
||||||
- **The Elder**: Unlock Rock Throwing ability. +10% passive health regeneration.
|
|
||||||
- **Bonemass**: +5% Size. +50 Carry Weight. +10 Damage to Clubs/Unarmed. +10 Rock Throwing Damage. Unlocks a **4th Food Slot**.
|
|
||||||
- **Moder**: Unlock True Form (Transformation ability).
|
|
||||||
- **Yagluth**: +5% Size. +50 Carry Weight. +10 Damage to Clubs/Unarmed. +5 Rock Throwing Damage. Unlocks a **5th Food Slot**.
|
|
||||||
- **The Queen**: Unlock Log Weapon (in True Form, interact with trees to wield them as weapons). True Form size is massively increased (2.5x).
|
|
||||||
- **Fader**: Your wielded trees can now instantly smash through the toughest materials in the Ashlands.
|
|
||||||
|
|
||||||
### Furling Progression
|
|
||||||
- **Base (No Bosses)**: Goblin head model. All weapon & combat skills gain 2x XP permanently.
|
|
||||||
- **Eikthyr**: Master of Shadows  sounds ≤15m are suppressed (near-silent movement).
|
|
||||||
- **The Elder**: The Wickerman  -50% Fire & Poison damage; arrows gain bonus fire damage.
|
|
||||||
- **Bonemass**: Dance of the Dead  Crafting meads, bombs, and ammo yields double quantity.
|
|
||||||
- **Moder**: The Man/Woman on the Silver Mountain  doubles trophy drops from normal enemies within 25m, drops bonus gold from starred enemies, doubles ore mining yield.
|
|
||||||
- **Yagluth**: The King is Dead, Hail to the King/Queen  while in the Plains biome, ALL skills gain 2x XP (including magic). HUD status icon shown.
|
|
||||||
- **The Queen**: In the Mist He/She Was Standing  blue (Eitr) foods last twice as long.
|
|
||||||
- **Fader**: Through Fire and Flames  permanently on fire (visual only), immune to fire damage, physical attacks set targets on fire.
|
|
||||||
|
|
||||||
### Aswid Progression
|
|
||||||
- **Base (No Bosses)**: Physical kills automatically consume enemies (if edible). Progressive stats (+1 Armor, +2 Damage, +1% Speed, +1% Jump per boss killed). All passive bonuses are doubled at night! You can cast Blood Magic items with infinite Eitr.
|
|
||||||
- **Eikthyr**: Bat Transformation (Night only). Vampiric Aura (heal 20% on magic AoE damage).
|
|
||||||
- **The Elder**: Bat Transformation (Always active).
|
|
||||||
- **Bonemass**: Superhuman Senses (Aura reveals untamed creatures).
|
|
||||||
- **Moder**: Freezing Blood (Permanent immunity to Freezing and Poison).
|
|
||||||
- **Yagluth**: Enslavement Power (E Key  Enslave non-tameable enemies).
|
|
||||||
- **The Queen**: Mist Form (H Key  Immune to physical/poison, double aura damage, weak to fire/frost/spirit. Breaks at sunrise).
|
|
||||||
- **Fader**: +10% Size, +30 Physical Damage. Physical kills automatically consume enemies.
|
|
||||||
|
|
||||||
### Skadi Progression
|
|
||||||
- **Base (No Bosses)**: Immune to Cold, Bonus Frost Damage, 50% Frost Resistance.
|
|
||||||
- **Eikthyr**: +20% Eitr Regen, Freezing to Cold, Cold Spell.
|
|
||||||
- **The Elder**: Drake Form (Cannot attack).
|
|
||||||
- **Bonemass**: Drake Form (Can attack).
|
|
||||||
- **Moder**: Moder Form (1 min duration, 10 min cooldown).
|
|
||||||
- **Yagluth**: Improved Cold Spell. Moder Form (1 min duration, 5 min cooldown).
|
|
||||||
- **The Queen**: Moder Form (Unlimited duration, no cooldown).
|
|
||||||
- **Fader**: Skeleton Dragon Form.
|
|
||||||
|
|
||||||
### Skeleton Progression
|
|
||||||
- **Base (No Bosses)**: +50 Max Health. Undead Diet (Cannot eat mortal food, no stamina bar).
|
|
||||||
- **Eikthyr**: Poison Skeleton Model, Poison Immunity, 5% Lifesteal, +80 Max Health.
|
|
||||||
- **The Elder**: 10% Lifesteal, Auto-Stun on First Hit, +110 Max Health.
|
|
||||||
- **Bonemass**: 15% Lifesteal, Poison Attacks, +140 Max Health.
|
|
||||||
- **Moder**: Fire Skeleton Model, 20% Lifesteal, Fire Aura, Enhanced Regen, +170 Max Health.
|
|
||||||
- **Yagluth**: 25% Lifesteal, Auto Resurrect, +200 Max Health.
|
|
||||||
- **The Queen**: 30% Lifesteal, Summon on Kill (Max 3 Skeletons), +230 Max Health.
|
|
||||||
- **Fader**: 35% Lifesteal, Max 5 Summons, +275 Max Health.
|
|
||||||
|
|
||||||
### Fenrir Progression
|
|
||||||
- **Base (No Bosses)**: Progressive stats (+3 Armor, +5 Damage, -10% Fall Damage, +3% Speed, +3% Jump per boss killed).
|
|
||||||
- **The Elder**: Wolf Form (Night).
|
|
||||||
- **Bonemass**: Wolf Form (Day/Night). Ulv Form (Night).
|
|
||||||
- **Moder**: Ulv Form (Day/Night). Fenring Form (Night).
|
|
||||||
- **Yagluth**: Cultist Form (Night  1 min duration, 10 min cooldown).
|
|
||||||
- **The Queen**: Fenring Form (Day/Night). Cultist Form (Night  1 min duration, 5 min cooldown).
|
|
||||||
- **Fader**: Cultist Form (Day/Night).
|
|
||||||
|
|
||||||
## Development & Feedback
|
|
||||||
|
|
||||||
This is a stable release of Races of Valheim, but the mod is actively in development! We plan to add more races, gameplay elements, and refine the mechanics in future updates.
|
|
||||||
Any feedback, bug reports, or suggestions for new features are more than welcome.
|
|
||||||
Please write to us on my Discord server: **https://discord.gg/dW72ch6Sw5**
|
|
||||||
|
|
||||||
## Changelog
|
|
||||||
|
|
||||||
**v1.3.2**
|
|
||||||
- **Aswid**: Blood Magic (Vampiric Aura) is now only active when blocking in Bat or Mist form. Base damage reduced by 50%.
|
|
||||||
- **Aswid**: Added thematic day/night transition messages ("what a horrible night to have a curse").
|
|
||||||
- **Bugfix**: Fixed an issue where the new automatic food consumption logic for Aswid physical kills failed to find the correct prefabs for basic animals like Deer and Boars.
|
|
||||||
|
|
||||||
**v1.3.1**
|
|
||||||
- **NEW RACE  Trol**: Added the sixth playable race, the Trol. Huge size, immense strength, rock throwing, and the ability to wield trees as weapons!
|
|
||||||
- **Trol Combat**: The Trol starts with increased size and carry weight, scaling stats as bosses are killed, and unlocking the ability to throw massive rocks at The Elder tier.
|
|
||||||
- **Trol True Form**: Unlocked at Moder, allowing you to transform. Once you defeat The Queen, you can look at trees while in True Form to rip a log out and use it as a massive 2-handed weapon!
|
|
||||||
- **Trol Stomachs**: As you progress, you unlock a 4th (Bonemass) and a 5th (Yagluth) stomach slot, allowing you to consume up to 5 foods simultaneously!
|
|
||||||
- **Bugfixes**: Fixed various item/food duplication bugs and polished the new eating logic to perfectly integrate with the native UI.
|
|
||||||
|
|
||||||
**v1.3.0**
|
|
||||||
- **NEW RACE  Furling**: Added the fifth playable race, the Furling (Goblin). Unique goblin head model, full progression tied to all 7 bosses.
|
|
||||||
- **Furling  Eikthyr (Master of Shadows)**: Sounds below 15m range are suppressed, making you nearly silent at night or in dungeons.
|
|
||||||
- **Furling  The Elder (The Wickerman)**: Gain -50% Fire and Poison damage resistance. Arrows gain bonus fire damage.
|
|
||||||
- **Furling  Bonemass (Dance of the Dead)**: Crafting meads, bombs, and ammo yields double the quantity.
|
|
||||||
- **Furling  Moder (The Man/Woman on the Silver Mountain)**: Trophy drops from normal enemies are doubled, starred enemies drop bonus coins, and ore mining yields are doubled.
|
|
||||||
- **Furling  Yagluth (The King is Dead, Hail to the King/Queen)**: In the Plains biome, the 2x XP multiplier extends to ALL skills (including Elemental and Blood Magic). A HUD status icon appears in the top-right when active.
|
|
||||||
- **Furling  The Queen (In the Mist He/She Was Standing)**: Eitr (blue) foods last twice as long for you.
|
|
||||||
- **Furling  Fader (Through Fire and Flames)**: You are permanently wreathed in native fire flames (SE_Burning visual, no damage, no HUD warning). Full fire immunity. All physical attacks set targets on fire.
|
|
||||||
- **Bugfix**: Fixed MineRock.RPC_Damage → MineRock.RPC_Hit Harmony patch after a Valheim update renamed the method.
|
|
||||||
|
|
||||||
**v1.2.0**
|
|
||||||
- **Multiplayer Sync**: Fully implemented visual syncing for Aswid forms (Bat, Mist) and Skadi forms (Bear, Wolf, Hatchling, Fader) so other players can see your transformations in multiplayer!
|
|
||||||
- **Aswid**: Scrapped the Fader (Surtling) visual override; reaching the final progression state now makes the player 10% taller and adds a flat +30 physical damage bonus.
|
|
||||||
- **Aswid**: Defeating enemies with physical attacks in the final state now automatically consumes them if you have food slots available.
|
|
||||||
- **General**: Eradicated remaining localizations of the old "Strigoi" name.
|
|
||||||
|
|
||||||
**v1.1.0**
|
|
||||||
- **Aswid**: Passive abilities (Speed and Jump) are now properly doubled during the night.
|
|
||||||
- **Aswid**: New Enslavement Power (Yagluth tier)! Press E on non-tameable, non-boss enemies to enslave them for 60 seconds (15-min cooldown). Enslaved thralls fight alongside you and drop standard loot.
|
|
||||||
- **Aswid**: Edible thralls are automatically consumed upon death, granting you their lifeforce (Fader tier).
|
|
||||||
- **Aswid**: Complete overhaul of the Food system. Added Mistlands and Ashlands creatures to the consumption map. Accurately scaled food stats based on creature health.
|
|
||||||
- **Aswid**: Excluded undead and inorganic creatures (Skeletons, Draugrs, Golems, etc.) from being edible.
|
|
||||||
- **Aswid**: Added a dynamic green light effect to all forms (Bonemass tier).
|
|
||||||
|
|
||||||
**v1.0.0**
|
|
||||||
- Initial release with 4 distinct races.
|
|
||||||
- Added Aswid life-draining and night transformations.
|
|
||||||
- Complete progression system tied to Valheim's bosses.
|
|
||||||
|
|
@ -149,7 +149,7 @@ namespace RacesOfValheim
|
||||||
sb.AppendLine(ModText.Get("rov_compendium_alfar_grafvaettir", Key(AlfarPowerConfig.GrafvaettirKey), F0(AlfarPowerConfig.GrafSeconds.Value), AlfarPowerConfig.GrafStone.Value, AlfarPowerConfig.GrafFlint.Value, F0(AlfarPowerConfig.GrafCooldown.Value)));
|
sb.AppendLine(ModText.Get("rov_compendium_alfar_grafvaettir", Key(AlfarPowerConfig.GrafvaettirKey), F0(AlfarPowerConfig.GrafSeconds.Value), AlfarPowerConfig.GrafStone.Value, AlfarPowerConfig.GrafFlint.Value, F0(AlfarPowerConfig.GrafCooldown.Value)));
|
||||||
}
|
}
|
||||||
if (state >= AlfarPowerConfig.UtsogState)
|
if (state >= AlfarPowerConfig.UtsogState)
|
||||||
sb.AppendLine(ModText.Get("rov_compendium_alfar_utsog", F0(AlfarPowerConfig.UtsogPercent.Value * 100f)));
|
sb.AppendLine(ModText.Get("rov_compendium_alfar_utsog", F0(AlfarPowerConfig.UtsogPercent.Value)));
|
||||||
if (state >= AlfarPowerConfig.KallState)
|
if (state >= AlfarPowerConfig.KallState)
|
||||||
sb.AppendLine(ModText.Get("rov_compendium_alfar_kall", Key(AlfarPowerConfig.KallKey), F0(AlfarPowerConfig.KallRadius.Value), F0(AlfarPowerConfig.KallCooldown.Value)));
|
sb.AppendLine(ModText.Get("rov_compendium_alfar_kall", Key(AlfarPowerConfig.KallKey), F0(AlfarPowerConfig.KallRadius.Value), F0(AlfarPowerConfig.KallCooldown.Value)));
|
||||||
if (state >= AlfarPowerConfig.LjosstormState)
|
if (state >= AlfarPowerConfig.LjosstormState)
|
||||||
|
|
@ -467,16 +467,62 @@ namespace RacesOfValheim
|
||||||
|
|
||||||
sb.AppendLine(ModText.Get("rov_compendium_aswid_benedictus_et_afflictus"));
|
sb.AppendLine(ModText.Get("rov_compendium_aswid_benedictus_et_afflictus"));
|
||||||
sb.AppendLine(ModText.Get("rov_compendium_aswid_take_no_fall_damage_physical", arm, dmg, spd, lifesteal, (AswidConfig.BloodMagicSkillGainMultiplier.Value).ToString("0.#")));
|
sb.AppendLine(ModText.Get("rov_compendium_aswid_take_no_fall_damage_physical", arm, dmg, spd, lifesteal, (AswidConfig.BloodMagicSkillGainMultiplier.Value).ToString("0.#")));
|
||||||
|
sb.AppendLine(ModText.Get("rov_compendium_aswid_undead_vigor",
|
||||||
|
Mathf.RoundToInt(AswidRace.GetStaminaBonus(state)),
|
||||||
|
Mathf.RoundToInt(AswidConfig.StaminaBonusPerState.Value),
|
||||||
|
Mathf.RoundToInt(AswidConfig.StaminaCostMultiplier.Value * 100f)));
|
||||||
|
sb.AppendLine(ModText.Get("rov_compendium_aswid_devour_diet",
|
||||||
|
Mathf.RoundToInt(AswidConfig.DevourHealthMultiplier.Value * 100f),
|
||||||
|
Mathf.RoundToInt(AswidConfig.EarlyStaminaShare.Value * 100f),
|
||||||
|
Mathf.RoundToInt(AswidConfig.DevourStaminaShare.Value * 100f)));
|
||||||
|
|
||||||
|
bool fireNow = AswidRace.HasFireWeakness(state);
|
||||||
|
bool fireGone = AswidConfig.FireWeaknessEnabled.Value && !fireNow;
|
||||||
|
if (AswidConfig.SunlightEnabled.Value || AswidConfig.FireWeaknessEnabled.Value || AswidConfig.PierceWeaknessEnabled.Value || AswidConfig.RunningWaterEnabled.Value)
|
||||||
|
sb.AppendLine(ModText.Get("rov_compendium_aswid_weaknesses"));
|
||||||
|
if (AswidConfig.SunlightEnabled.Value)
|
||||||
|
sb.AppendLine(ModText.Get("rov_compendium_aswid_weakness_sunlight",
|
||||||
|
Mathf.RoundToInt(AswidConfig.SunHealthRegenPenalty.Value * 100f),
|
||||||
|
Mathf.RoundToInt(AswidConfig.SunStaminaRegenPenalty.Value * 100f),
|
||||||
|
Mathf.RoundToInt(AswidConfig.SunSpeedPenalty.Value * 100f),
|
||||||
|
AswidConfig.SunHealthLossPerSecond.Value.ToString("0.#"),
|
||||||
|
Mathf.RoundToInt(AswidConfig.SunHealthFloor.Value * 100f)));
|
||||||
|
if (fireNow)
|
||||||
|
sb.AppendLine(ModText.Get("rov_compendium_aswid_weakness_fire", Mathf.RoundToInt(AswidConfig.FireWeakness.Value * 100f)));
|
||||||
|
else if (fireGone)
|
||||||
|
sb.AppendLine(ModText.Get("rov_compendium_aswid_weakness_fire_gone"));
|
||||||
|
if (AswidConfig.PierceWeaknessEnabled.Value)
|
||||||
|
sb.AppendLine(ModText.Get("rov_compendium_aswid_weakness_pierce", Mathf.RoundToInt(AswidConfig.PierceWeakness.Value * 100f)));
|
||||||
|
if (AswidConfig.RunningWaterEnabled.Value)
|
||||||
|
sb.AppendLine(ModText.Get("rov_compendium_aswid_weakness_water",
|
||||||
|
AswidConfig.SwimStaminaMultiplier.Value.ToString("0.#"),
|
||||||
|
AswidConfig.SeaHealthLossPerSecond.Value.ToString("0.#"),
|
||||||
|
AswidConfig.SeaStaminaDrainPerSecond.Value.ToString("0.#")));
|
||||||
|
|
||||||
sb.AppendLine(ModText.Get("rov_compendium_aswid_vampiric_aura_passive_toggle"));
|
sb.AppendLine(ModText.Get("rov_compendium_aswid_vampiric_aura_passive_toggle"));
|
||||||
sb.AppendLine(ModText.Get("rov_compendium_aswid_always_active_every_form_with", auraRadiusDay, auraRadiusNight, auraExecute));
|
sb.AppendLine(ModText.Get("rov_compendium_aswid_always_active_every_form_with", auraRadiusDay, auraRadiusNight, auraExecute));
|
||||||
|
int batAuraUnlock = AswidConfig.BatAuraUnlockState.Value;
|
||||||
|
if (AswidRace.BatAuraAllowed(state))
|
||||||
|
sb.AppendLine(ModText.Get("rov_compendium_aswid_aura_bat_on"));
|
||||||
|
else if (batAuraUnlock > 0)
|
||||||
|
sb.AppendLine(ModText.Get("rov_compendium_aswid_aura_bat_locked", BossProgressionManager.GetBossTokenForState(batAuraUnlock)));
|
||||||
|
else
|
||||||
|
sb.AppendLine(ModText.Get("rov_compendium_aswid_aura_bat_never"));
|
||||||
|
|
||||||
// The live figure, so the entry cannot drift from the code: it is the same yardstick
|
// The live figure, so the entry cannot drift from the code: it is the same yardstick
|
||||||
// the Sverm's own claws are measured against, which is what keeps the three races even.
|
// the Sverm's own claws are measured against, which is what keeps the three races even.
|
||||||
sb.AppendLine(ModText.Get("rov_compendium_aswid_claws_beast_s_grows_blackened", (RaceClawsConfig.DurationSeconds.Value).ToString("0"), (SvermClaws.GetDamagePercent(state) * 100f).ToString("0")));
|
sb.AppendLine(ModText.Get("rov_compendium_aswid_claws_beast_s_grows_blackened", (RaceClawsConfig.DurationSeconds.Value).ToString("0"), (SvermClaws.GetDamagePercent(state) * 100f).ToString("0")));
|
||||||
|
|
||||||
if (state >= 2)
|
if (state >= 2)
|
||||||
|
{
|
||||||
sb.AppendLine(ModText.Get("rov_compendium_aswid_bat_form_g_key_night"));
|
sb.AppendLine(ModText.Get("rov_compendium_aswid_bat_form_g_key_night"));
|
||||||
|
if (AswidConfig.UsesFreeBatFlight())
|
||||||
|
sb.AppendLine(ModText.Get("rov_compendium_aswid_bat_free_flight"));
|
||||||
|
else
|
||||||
|
sb.AppendLine(ModText.Get("rov_compendium_aswid_bat_flight",
|
||||||
|
AswidConfig.BatPoweredStaminaPerSecond.Value.ToString("0.#"),
|
||||||
|
AswidConfig.BatSprintStaminaPerSecond.Value.ToString("0.#")));
|
||||||
|
}
|
||||||
|
|
||||||
if (state >= 2)
|
if (state >= 2)
|
||||||
sb.AppendLine(ModText.Get("rov_compendium_aswid_tame_u_key_tame_boar"));
|
sb.AppendLine(ModText.Get("rov_compendium_aswid_tame_u_key_tame_boar"));
|
||||||
|
|
@ -543,7 +589,10 @@ namespace RacesOfValheim
|
||||||
sb.AppendLine(ModText.Get("rov_compendium_fenrir_cursed_claws_s_wolf_s", (RaceClawsConfig.DurationSeconds.Value).ToString("0"), (SvermClaws.GetDamagePercent(state) * 100f).ToString("0")));
|
sb.AppendLine(ModText.Get("rov_compendium_fenrir_cursed_claws_s_wolf_s", (RaceClawsConfig.DurationSeconds.Value).ToString("0"), (SvermClaws.GetDamagePercent(state) * 100f).ToString("0")));
|
||||||
|
|
||||||
if (state >= 3)
|
if (state >= 3)
|
||||||
|
{
|
||||||
sb.AppendLine(ModText.Get("rov_compendium_fenrir_wolf_form_g_key_night"));
|
sb.AppendLine(ModText.Get("rov_compendium_fenrir_wolf_form_g_key_night"));
|
||||||
|
sb.AppendLine(ModText.Get("rov_compendium_fenrir_senses_in_form", Mathf.RoundToInt(FenrirConfig.SensesRadius.Value)));
|
||||||
|
}
|
||||||
|
|
||||||
if (state >= 4)
|
if (state >= 4)
|
||||||
{
|
{
|
||||||
|
|
@ -676,7 +725,18 @@ namespace RacesOfValheim
|
||||||
sb.AppendLine((state <= BossProgressionManager.MinState ? ModText.Get("rov_compendium_skeleton_stand_at_first_eight_standings") : ModText.Get("rov_compendium_skeleton_stand_at_eight_standings_earned", state, BossProgressionManager.GetBossTokenForState(state))));
|
sb.AppendLine((state <= BossProgressionManager.MinState ? ModText.Get("rov_compendium_skeleton_stand_at_first_eight_standings") : ModText.Get("rov_compendium_skeleton_stand_at_eight_standings_earned", state, BossProgressionManager.GetBossTokenForState(state))));
|
||||||
|
|
||||||
sb.AppendLine(ModText.Get("rov_compendium_skeleton_undead_diet"));
|
sb.AppendLine(ModText.Get("rov_compendium_skeleton_undead_diet"));
|
||||||
sb.AppendLine(ModText.Get("rov_compendium_skeleton_no_hunger_moves_no_meal", (health).ToString("0")));
|
bool eats = SkeletonConfig.EatsMortalFood.Value, tires = SkeletonConfig.FeelsFatigue.Value;
|
||||||
|
if (!eats && !tires)
|
||||||
|
{
|
||||||
|
sb.AppendLine(ModText.Get("rov_compendium_skeleton_no_hunger_moves_no_meal", (health).ToString("0")));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// A player who picked one of the "Mortal Habits" reads what they actually have.
|
||||||
|
string diet = eats ? ModText.Get("rov_compendium_skeleton_diet_mortal") : ModText.Get("rov_compendium_skeleton_diet_bones", (health).ToString("0"));
|
||||||
|
string effort = tires ? ModText.Get("rov_compendium_skeleton_effort_mortal") : ModText.Get("rov_compendium_skeleton_effort_none");
|
||||||
|
sb.AppendLine(diet + " " + effort + "\n");
|
||||||
|
}
|
||||||
|
|
||||||
sb.AppendLine(ModText.Get("rov_compendium_skeleton_bones_blades"));
|
sb.AppendLine(ModText.Get("rov_compendium_skeleton_bones_blades"));
|
||||||
sb.AppendLine(ModText.Get("rov_compendium_skeleton_blades_points_find_little_cut"));
|
sb.AppendLine(ModText.Get("rov_compendium_skeleton_blades_points_find_little_cut"));
|
||||||
|
|
@ -814,8 +874,8 @@ namespace RacesOfValheim
|
||||||
int foodDuration = Mathf.RoundToInt(TrentaConfig.FoodDurationMultiplier);
|
int foodDuration = Mathf.RoundToInt(TrentaConfig.FoodDurationMultiplier);
|
||||||
|
|
||||||
int purpleRainRadius = Mathf.RoundToInt(TrentaConfig.PurpleRainRadius);
|
int purpleRainRadius = Mathf.RoundToInt(TrentaConfig.PurpleRainRadius);
|
||||||
int purpleRainHeal = Mathf.RoundToInt(TrentaConfig.PurpleRainHealAmount);
|
int purpleRainHeal = Mathf.RoundToInt(TrentaConfig.PurpleRainHealFor(Player.m_localPlayer));
|
||||||
int purpleRainPoison = Mathf.RoundToInt(TrentaConfig.PurpleRainPoisonDamage);
|
int purpleRainPoison = Mathf.RoundToInt(TrentaConfig.PurpleRainPoisonFor(Player.m_localPlayer));
|
||||||
int purpleRainCooldown = Mathf.RoundToInt(TrentaConfigManagement.PurpleRainCooldown.Value);
|
int purpleRainCooldown = Mathf.RoundToInt(TrentaConfigManagement.PurpleRainCooldown.Value);
|
||||||
int purpleRainMuspellCooldown = Mathf.RoundToInt(TrentaConfigManagement.MuspellPurpleRainCooldown.Value);
|
int purpleRainMuspellCooldown = Mathf.RoundToInt(TrentaConfigManagement.MuspellPurpleRainCooldown.Value);
|
||||||
|
|
||||||
|
|
|
||||||
64
JotunnModStub/RaceEyeTuning.cs
Normal file
|
|
@ -0,0 +1,64 @@
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace RacesOfValheim
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Hand corrections for every race that hangs eyes on the face, per body and per eye. Per body
|
||||||
|
/// because the two bodies put their painted eyes in different places (PlayerFace); per eye
|
||||||
|
/// because the face is not symmetric enough for one set to fit both. Left and right are the
|
||||||
|
/// character's own.
|
||||||
|
///
|
||||||
|
/// Every value is a delta on the placement the race's own code computes: zeros (and size 1)
|
||||||
|
/// change nothing. They were dialled in on screen with Configuration Manager sliders
|
||||||
|
/// (playtest, 2026-10-27) and then written down here; the sliders are gone.
|
||||||
|
/// </summary>
|
||||||
|
public static class RaceEyeTuning
|
||||||
|
{
|
||||||
|
/// <summary>One eye's corrections. Metres for the offsets, degrees for the rotations.</summary>
|
||||||
|
public sealed class Eye
|
||||||
|
{
|
||||||
|
public float Forward, Height, Separation, RotX, RotY, RotZ;
|
||||||
|
public float Size = 1f;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static readonly Eye Untouched = new Eye();
|
||||||
|
|
||||||
|
// [race] -> { male left, male right, female left, female right }
|
||||||
|
private static readonly Dictionary<string, Eye[]> tunings = new Dictionary<string, Eye[]>
|
||||||
|
{
|
||||||
|
[AlfarConfig.RaceId] = new[]
|
||||||
|
{
|
||||||
|
new Eye(),
|
||||||
|
new Eye { Separation = 0.009f },
|
||||||
|
new Eye { Separation = 0.006f, RotX = -17.524f },
|
||||||
|
new Eye { Separation = 0.015f, RotX = -17.524f },
|
||||||
|
},
|
||||||
|
["Aswid"] = new[]
|
||||||
|
{
|
||||||
|
new Eye { Height = -0.005f, Separation = -0.005f, Size = 1.273f, RotX = 6.49f, RotY = 4.544f, RotZ = 4.544f },
|
||||||
|
new Eye { Forward = -0.002f, Height = -0.005f, Separation = 0.004f, Size = 1.444f, RotZ = 6.49f },
|
||||||
|
new Eye { Forward = -0.006f, Height = -0.010f, Size = 1.314f, RotX = -14.279f, RotY = -5.841f, RotZ = -1.298f },
|
||||||
|
new Eye { Forward = -0.006f, Height = -0.012f, Separation = 0.011f, Size = 1.324f, RotX = 1.947f, RotY = 3.245f, RotZ = 4.544f },
|
||||||
|
},
|
||||||
|
[DvergarConfig.RaceId] = new[]
|
||||||
|
{
|
||||||
|
new Eye { Forward = -0.003f, Size = 1.05f },
|
||||||
|
new Eye { Forward = -0.004f, Separation = 0.005f },
|
||||||
|
new Eye { Forward = -0.011f, Separation = 0.005f, Size = 1.616f },
|
||||||
|
new Eye { Forward = -0.015f, Separation = 0.013f, Size = 1.616f },
|
||||||
|
},
|
||||||
|
// The Sverm's helmet hides its eyes, so it keeps the code's own placement.
|
||||||
|
};
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The corrections for one eye of the body this player is wearing right now. Side is the
|
||||||
|
/// races' own convention: negative is offset against the head frame's right axis, which is
|
||||||
|
/// the character's left eye. Never null.
|
||||||
|
/// </summary>
|
||||||
|
public static Eye For(string race, Player player, float side)
|
||||||
|
{
|
||||||
|
if (!tunings.TryGetValue(race, out Eye[] set)) return Untouched;
|
||||||
|
return set[(PlayerFace.IsFemale(player) ? 2 : 0) + (side < 0f ? 0 : 1)];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -25,11 +25,13 @@ namespace RacesOfValheim
|
||||||
/// which means everything downstream - acquiring, chasing, retaliating, giving up - is vanilla
|
/// which means everything downstream - acquiring, chasing, retaliating, giving up - is vanilla
|
||||||
/// behaviour rather than anything reimplemented here.
|
/// behaviour rather than anything reimplemented here.
|
||||||
///
|
///
|
||||||
/// WHERE IT RUNS. On the client that owns the mob's AI, which is the only one whose UpdateTarget
|
/// WHERE IT LIVES. On the creature's own ZDO: who it is angry at and until when, in network time.
|
||||||
/// matters and the only one that runs Character.ApplyDamage for it. BaseAI.OnDamaged is reached
|
/// The AI that reads it runs on whichever machine owns the creature, and that can change in the
|
||||||
/// through the character's damage callback on exactly that machine, so the record is made where
|
/// middle of a fight (the owner walks off or logs out). A grudge kept in one machine's memory
|
||||||
/// it will be read. Nothing is replicated and nothing needs to be: another client's copy of the
|
/// went with it, and the new owner's copy of the creature made peace on its next UpdateTarget.
|
||||||
/// same mob is not the one deciding who it chases.
|
/// On the ZDO the new owner reads the same grudge. Only the owner writes it: a hit reaches the
|
||||||
|
/// owner through Character.Damage's RPC anyway, and kin owned elsewhere are told by an RPC of
|
||||||
|
/// our own (RpcName), so no client writes a ZDO it does not own.
|
||||||
///
|
///
|
||||||
/// Vanilla has its own version of this idea in BaseAI.SetAggravated, and it is not usable here:
|
/// Vanilla has its own version of this idea in BaseAI.SetAggravated, and it is not usable here:
|
||||||
/// it does nothing unless the prefab sets m_aggravatable, which only the dvergr and the seekers
|
/// it does nothing unless the prefab sets m_aggravatable, which only the dvergr and the seekers
|
||||||
|
|
@ -37,67 +39,96 @@ namespace RacesOfValheim
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static class RaceGrudge
|
public static class RaceGrudge
|
||||||
{
|
{
|
||||||
private struct Grudge
|
private const string RpcName = "RacesOfValheim_Grudge";
|
||||||
{
|
|
||||||
public ZDOID Attacker;
|
|
||||||
public float Until;
|
|
||||||
}
|
|
||||||
|
|
||||||
// One grudge per mob, against the last thing that hit it. A creature can only chase one
|
// One grudge per creature, against the last player that hit it. A creature can only chase
|
||||||
// target anyway, and if two players of the same race are both poking it, the one it wants
|
// one target anyway, and if two players of the same race are both poking it, the one it
|
||||||
// is whoever hit it last.
|
// wants is whoever hit it last.
|
||||||
private static readonly Dictionary<ZDOID, Grudge> grudges = new Dictionary<ZDOID, Grudge>();
|
private static readonly KeyValuePair<int, int> AttackerKey = ZDO.GetHashZDOID("RacesOfValheim_GrudgeAttacker");
|
||||||
private static float lastSweep = 0f;
|
private static readonly int UntilKey = "RacesOfValheim_GrudgeUntil".GetStableHashCode();
|
||||||
|
|
||||||
private static float Duration => FactionsConfig.GrudgeSeconds;
|
private static float Duration => FactionsConfig.GrudgeSeconds;
|
||||||
|
|
||||||
|
// Network time, the same on every machine, so an end time written by one owner means the
|
||||||
|
// same thing to the next. Milliseconds in a long: ZDO has no double.
|
||||||
|
private static long NowMs => ZNet.instance != null ? (long)(ZNet.instance.GetTimeSeconds() * 1000.0) : 0L;
|
||||||
|
|
||||||
|
private static ZDO ZdoOf(Character character)
|
||||||
|
{
|
||||||
|
if (character == null || ZDOMan.instance == null) return null;
|
||||||
|
ZDOID id = character.GetZDOID();
|
||||||
|
return id.IsNone() ? null : ZDOMan.instance.GetZDO(id);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// True while <paramref name="monster"/> is owed a hit by <paramref name="player"/>. Both
|
/// True while <paramref name="monster"/> is owed a hit by <paramref name="player"/>. Both
|
||||||
/// truce postfixes ask this first and leave IsEnemy alone when it answers yes.
|
/// truce postfixes ask this first and leave IsEnemy alone when it answers yes. Read on any
|
||||||
|
/// machine; it only matters on the owner's.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static bool Holds(Character monster, Character player)
|
public static bool Holds(Character monster, Character player)
|
||||||
{
|
{
|
||||||
if (monster == null || player == null) return false;
|
if (monster == null || player == null) return false;
|
||||||
if (Duration <= 0f) return false;
|
if (Duration <= 0f) return false;
|
||||||
|
|
||||||
if (!grudges.TryGetValue(monster.GetZDOID(), out Grudge grudge)) return false;
|
ZDO zdo = ZdoOf(monster);
|
||||||
if (Time.time >= grudge.Until) return false;
|
if (zdo == null) return false;
|
||||||
|
|
||||||
return grudge.Attacker == player.GetZDOID();
|
long until = zdo.GetLong(UntilKey, 0L);
|
||||||
}
|
if (until == 0L || NowMs >= until) return false;
|
||||||
|
|
||||||
public static void Remember(Character monster, Character attacker)
|
return zdo.GetZDOID(AttackerKey) == player.GetZDOID();
|
||||||
{
|
|
||||||
if (monster == null || attacker == null) return;
|
|
||||||
if (Duration <= 0f) return;
|
|
||||||
|
|
||||||
grudges[monster.GetZDOID()] = new Grudge
|
|
||||||
{
|
|
||||||
Attacker = attacker.GetZDOID(),
|
|
||||||
Until = Time.time + Duration
|
|
||||||
};
|
|
||||||
|
|
||||||
Sweep();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Drops grudges nobody is owed any more. At most once per duration: a fight is a burst of
|
/// Writes the grudge on the creature's ZDO if this machine owns it, and otherwise asks the
|
||||||
/// damage events and the list should not be walked on each one.
|
/// owner to. Returns true when it was written here.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private static void Sweep()
|
public static bool Remember(Character monster, Character attacker)
|
||||||
{
|
{
|
||||||
if (Time.time - lastSweep < Duration) return;
|
if (monster == null || attacker == null) return false;
|
||||||
lastSweep = Time.time;
|
if (Duration <= 0f) return false;
|
||||||
|
|
||||||
List<ZDOID> expired = null;
|
ZNetView nview = monster.GetComponent<ZNetView>();
|
||||||
foreach (var entry in grudges)
|
if (nview == null || !nview.IsValid()) return false;
|
||||||
|
|
||||||
|
if (!nview.IsOwner())
|
||||||
{
|
{
|
||||||
if (Time.time < entry.Value.Until) continue;
|
nview.InvokeRPC(RpcName, attacker.GetZDOID());
|
||||||
if (expired == null) expired = new List<ZDOID>();
|
return false;
|
||||||
expired.Add(entry.Key);
|
}
|
||||||
|
|
||||||
|
Write(nview.GetZDO(), attacker.GetZDOID());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void Write(ZDO zdo, ZDOID attacker)
|
||||||
|
{
|
||||||
|
zdo.Set(AttackerKey, attacker);
|
||||||
|
zdo.Set(UntilKey, NowMs + (long)(Duration * 1000f));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Every creature can be told about a grudge by a machine that does not own it. ZNetView's
|
||||||
|
/// InvokeRPC routes to the owner, so the handler always runs where the ZDO may be written,
|
||||||
|
/// and the owner checks it is still the owner: ownership can move while the RPC travels.
|
||||||
|
/// </summary>
|
||||||
|
[HarmonyPatch(typeof(Character), "Awake")]
|
||||||
|
public static class Character_Awake_GrudgeRpc_Patch
|
||||||
|
{
|
||||||
|
public static void Postfix(Character __instance)
|
||||||
|
{
|
||||||
|
if (__instance.IsPlayer()) return;
|
||||||
|
ZNetView nview = __instance.GetComponent<ZNetView>();
|
||||||
|
if (nview == null || !nview.IsValid()) return;
|
||||||
|
|
||||||
|
nview.Register<ZDOID>(RpcName, (sender, attacker) =>
|
||||||
|
{
|
||||||
|
if (__instance == null || !nview.IsValid() || !nview.IsOwner()) return;
|
||||||
|
if (attacker.IsNone() || Duration <= 0f) return;
|
||||||
|
Write(nview.GetZDO(), attacker);
|
||||||
|
__instance.GetBaseAI()?.Alert();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
if (expired == null) return;
|
|
||||||
foreach (ZDOID id in expired) grudges.Remove(id);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -121,6 +152,81 @@ namespace RacesOfValheim
|
||||||
if (monster == null || monster.IsPlayer()) return;
|
if (monster == null || monster.IsPlayer()) return;
|
||||||
|
|
||||||
Remember(monster, attacker);
|
Remember(monster, attacker);
|
||||||
|
if (FactionsConfig.GrudgeSpreads && attacker is Player player) SpreadToKin(monster, player);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// How deep we are inside one of vanilla's hit filters (see StrikeScope). A counter rather
|
||||||
|
// than a bool because Projectile.OnHit calls DoAOE, and the inner exit must not end the
|
||||||
|
// outer scope.
|
||||||
|
private static int strikeDepth = 0;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// True while vanilla is deciding whether <paramref name="attacker"/>'s own weapon, arrow or
|
||||||
|
/// area hit lands. Both truce postfixes stand down for that question: the truce is about
|
||||||
|
/// who a creature attacks, never about whether the player is allowed to strike it.
|
||||||
|
/// </summary>
|
||||||
|
public static bool PlayerStrikes(Character attacker)
|
||||||
|
{
|
||||||
|
return strikeDepth > 0 && attacker != null && attacker.IsPlayer();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// THE PLAYER COULD NOT HIT THEIR OWN FACTION AT ALL. Valheim 1.0's hit filters (Attack's
|
||||||
|
/// melee and area swings, Projectile's direct hit, its AoE and its IsValidTarget, Aoe's
|
||||||
|
/// ShouldHit) ask BaseAI.IsEnemy(attacker, target) and skip the target when it answers false
|
||||||
|
/// and the attacker is a player without PvP on - vanilla's guard for tames. Our truce
|
||||||
|
/// answers false for every allied creature, so the blow passed through it, it took no
|
||||||
|
/// damage, BaseAI.OnDamaged never ran and no grudge was ever born. That is both reports at
|
||||||
|
/// once: "it will not allow me" to attack, and kin that never fight back, group grudge on or
|
||||||
|
/// off, because nobody was ever hit. With PvP on the filter let the hit through, which is
|
||||||
|
/// why it looked fine in some tests.
|
||||||
|
///
|
||||||
|
/// The scope is open only around those six methods, so everything else that asks IsEnemy
|
||||||
|
/// with the player first keeps the truce: the green health bar on allied creatures, sneaking
|
||||||
|
/// past them, the Aswid's aura leaving kin alone.
|
||||||
|
/// </summary>
|
||||||
|
[HarmonyPatch]
|
||||||
|
public static class StrikeScope
|
||||||
|
{
|
||||||
|
public static IEnumerable<System.Reflection.MethodBase> TargetMethods()
|
||||||
|
{
|
||||||
|
yield return AccessTools.Method(typeof(Attack), "DoMeleeAttack");
|
||||||
|
yield return AccessTools.Method(typeof(Attack), "DoAreaAttack");
|
||||||
|
yield return AccessTools.Method(typeof(Projectile), "DoAOE");
|
||||||
|
yield return AccessTools.Method(typeof(Projectile), "IsValidTarget");
|
||||||
|
yield return AccessTools.Method(typeof(Projectile), "OnHit");
|
||||||
|
yield return AccessTools.Method(typeof(Aoe), "ShouldHit");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void Prefix() => strikeDepth++;
|
||||||
|
|
||||||
|
// Finalizer rather than Postfix: the count has to come down even when the method
|
||||||
|
// throws, or every IsEnemy afterwards would ignore the truce.
|
||||||
|
public static void Finalizer() => strikeDepth--;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Vanilla's Dvergr camp, for every faction ("Grudge spreads to kin", off by default): hit
|
||||||
|
/// a creature that is at peace with you and its kin around it take up the same grudge.
|
||||||
|
///
|
||||||
|
/// Kin this machine owns are written here; kin owned by another player's machine are told
|
||||||
|
/// through RpcName, and their owner writes the grudge and alerts them.
|
||||||
|
/// </summary>
|
||||||
|
private static void SpreadToKin(Character monster, Player player)
|
||||||
|
{
|
||||||
|
string race = FactionHostilityPatch.GetPlayerRace(player);
|
||||||
|
if (!FactionHostilityPatch.IsAlliedMob(race, monster.gameObject.name)) return;
|
||||||
|
|
||||||
|
Vector3 center = monster.transform.position;
|
||||||
|
float radius = FactionsConfig.GrudgeSpreadMeters;
|
||||||
|
foreach (Character other in Character.GetAllCharacters())
|
||||||
|
{
|
||||||
|
if (other == null || other == monster || other.IsPlayer() || other.IsDead() || other.IsTamed()) continue;
|
||||||
|
if (Vector3.Distance(other.transform.position, center) > radius) continue;
|
||||||
|
if (!FactionHostilityPatch.IsAlliedMob(race, other.gameObject.name)) continue;
|
||||||
|
|
||||||
|
if (Remember(other, player)) other.GetBaseAI()?.Alert();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,9 @@ namespace RacesOfValheim
|
||||||
|
|
||||||
if (a == null || b == null) return;
|
if (a == null || b == null) return;
|
||||||
|
|
||||||
|
// The player's own blow lands on kin too. See RaceGrudge.StrikeScope.
|
||||||
|
if (RaceGrudge.PlayerStrikes(a)) return;
|
||||||
|
|
||||||
Character playerCharacter = a.IsPlayer() ? a : (b.IsPlayer() ? b : null);
|
Character playerCharacter = a.IsPlayer() ? a : (b.IsPlayer() ? b : null);
|
||||||
Character monster = a.IsPlayer() ? b : (b.IsPlayer() ? a : null);
|
Character monster = a.IsPlayer() ? b : (b.IsPlayer() ? a : null);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -167,6 +167,19 @@ namespace RacesOfValheim
|
||||||
return Input.GetMouseButtonDown(mouseButton) || PadAttackDown(mouseButton);
|
return Input.GetMouseButtonDown(mouseButton) || PadAttackDown(mouseButton);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Nothing in either hand and not building. The pad has no spare button, so a race power
|
||||||
|
/// that needs one borrows the secondary attack under this condition only: with a weapon or
|
||||||
|
/// a tool in hand that button stays the item's, as in vanilla.
|
||||||
|
/// </summary>
|
||||||
|
public static bool EmptyHanded(Player player)
|
||||||
|
{
|
||||||
|
if (player == null || player.InPlaceMode()) return false;
|
||||||
|
var hands = Traverse.Create(player);
|
||||||
|
return hands.Field<ItemDrop.ItemData>("m_rightItem").Value == null &&
|
||||||
|
hands.Field<ItemDrop.ItemData>("m_leftItem").Value == null;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>Held-down counterpart of <see cref="AttackDown"/>.</summary>
|
/// <summary>Held-down counterpart of <see cref="AttackDown"/>.</summary>
|
||||||
public static bool AttackHeld(int mouseButton)
|
public static bool AttackHeld(int mouseButton)
|
||||||
{
|
{
|
||||||
|
|
@ -202,7 +215,7 @@ namespace RacesOfValheim
|
||||||
private static bool loggedOpen;
|
private static bool loggedOpen;
|
||||||
private static bool loggedClosed;
|
private static bool loggedClosed;
|
||||||
|
|
||||||
private static bool RadialOpen
|
internal static bool RadialOpen
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -115,15 +115,18 @@ namespace RacesOfValheim
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>F8 turns the reach readout on and off.</summary>
|
/// <summary>The debug key (DebugConfig, F8 by default) turns the reach readout on and off.</summary>
|
||||||
[HarmonyPatch(typeof(Player), "Update")]
|
[HarmonyPatch(typeof(Player), "Update")]
|
||||||
internal static class RaceMeleeReachDebugKey
|
internal static class RaceMeleeReachDebugKey
|
||||||
{
|
{
|
||||||
private static void Postfix(Player __instance)
|
private static void Postfix(Player __instance)
|
||||||
{
|
{
|
||||||
if (__instance != Player.m_localPlayer || !Input.GetKeyDown(KeyCode.F8)) return;
|
if (__instance != Player.m_localPlayer || !DebugConfig.EnableDebugKey.Value) return;
|
||||||
|
if (!DebugConfig.DebugKey.Value.IsDownIgnoringHeldKeys()) return;
|
||||||
RaceMeleeReach.DebugOn = !RaceMeleeReach.DebugOn;
|
RaceMeleeReach.DebugOn = !RaceMeleeReach.DebugOn;
|
||||||
__instance.Message(MessageHud.MessageType.TopLeft, $"[RoV reach] debug {(RaceMeleeReach.DebugOn ? "on" : "off")}");
|
__instance.Message(MessageHud.MessageType.TopLeft, $"[RoV reach] debug {(RaceMeleeReach.DebugOn ? "on" : "off")}");
|
||||||
|
AlfarMiner.DebugReport(__instance);
|
||||||
|
AlfarDroneAI.DebugReport(__instance);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -44,6 +44,8 @@ namespace RacesOfValheim
|
||||||
|
|
||||||
prefab.AddComponent<RaceMenuWardBehavior>();
|
prefab.AddComponent<RaceMenuWardBehavior>();
|
||||||
|
|
||||||
|
Restyle(prefab);
|
||||||
|
|
||||||
PieceConfig config = new PieceConfig
|
PieceConfig config = new PieceConfig
|
||||||
{
|
{
|
||||||
Name = "$rov_piece_racemenuward_name",
|
Name = "$rov_piece_racemenuward_name",
|
||||||
|
|
@ -60,6 +62,44 @@ namespace RacesOfValheim
|
||||||
PieceManager.Instance.AddPiece(new CustomPiece(prefab, fixReference: false, config));
|
PieceManager.Instance.AddPiece(new CustomPiece(prefab, fixReference: false, config));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------- the look
|
||||||
|
/// <summary>Seidr blue in place of the Ward's hearth orange: every race builds this, so no race's colour.</summary>
|
||||||
|
private static readonly Color Glow = new Color(0.55f, 0.62f, 1f, 1f);
|
||||||
|
/// <summary>A colder stone, so it reads as a different thing from the vanilla Ward across a base.</summary>
|
||||||
|
private static readonly Color StoneTint = new Color(0.78f, 0.82f, 0.92f, 1f);
|
||||||
|
/// <summary>Narrower and taller than the Ward, on a plinth: a statue rather than a waystone.</summary>
|
||||||
|
private static readonly Vector3 StatueShape = new Vector3(0.9f, 1.12f, 0.9f);
|
||||||
|
private const float PlinthWidth = 1.3f;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Odin's stone on a plinth, glowing blue. The statue, its light and its sparks are lifted by the
|
||||||
|
/// plinth's MEASURED height, so a different plinth model needs no new offset.
|
||||||
|
/// </summary>
|
||||||
|
private static void Restyle(GameObject prefab)
|
||||||
|
{
|
||||||
|
Transform statue = prefab.transform.Find("new");
|
||||||
|
if (statue == null)
|
||||||
|
{
|
||||||
|
Jotunn.Logger.LogWarning("guard_stone has no 'new' model; the Race Menu Ward keeps the vanilla look.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
PieceLook.Tint(statue, StoneTint);
|
||||||
|
PieceLook.Rehue(prefab.transform, Glow);
|
||||||
|
statue.localScale = Vector3.Scale(statue.localScale, StatueShape);
|
||||||
|
|
||||||
|
GameObject plinth = ModelBorrow.Attach(prefab.transform, "WardPlinth", "stone_floor_2x2",
|
||||||
|
Vector3.zero, Quaternion.identity, PlinthWidth,
|
||||||
|
"RaceMenuWard", activeOnly: true);
|
||||||
|
float lift = ModelBorrow.HeightOf(plinth);
|
||||||
|
|
||||||
|
foreach (string child in new[] { "new", "WayEffect", "GuidePoint" })
|
||||||
|
{
|
||||||
|
Transform part = prefab.transform.Find(child);
|
||||||
|
if (part != null) part.localPosition += Vector3.up * lift;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Marks a world as already having its starter ward, so it is placed exactly once rather
|
// Marks a world as already having its starter ward, so it is placed exactly once rather
|
||||||
// than every time someone loads in.
|
// than every time someone loads in.
|
||||||
private const string PlacedKey = "RacesOfValheim_StarterWardPlaced";
|
private const string PlacedKey = "RacesOfValheim_StarterWardPlaced";
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ namespace RacesOfValheim
|
||||||
{
|
{
|
||||||
public const string PluginGUID = "com.nandor.racesofvalheim";
|
public const string PluginGUID = "com.nandor.racesofvalheim";
|
||||||
public const string PluginName = "Races Of Valheim";
|
public const string PluginName = "Races Of Valheim";
|
||||||
public const string PluginVersion = "1.6.0";
|
public const string PluginVersion = "1.6.11";
|
||||||
|
|
||||||
private readonly Harmony harmony = new Harmony(PluginGUID);
|
private readonly Harmony harmony = new Harmony(PluginGUID);
|
||||||
|
|
||||||
|
|
@ -47,6 +47,7 @@ namespace RacesOfValheim
|
||||||
// Not a race either: a tool any race can craft, so it sits beside the vulture rather
|
// Not a race either: a tool any race can craft, so it sits beside the vulture rather
|
||||||
// than inside the alphabetical run above.
|
// than inside the alphabetical run above.
|
||||||
TrolsHammerConfig.Bind(Config);
|
TrolsHammerConfig.Bind(Config);
|
||||||
|
ShrinkHammerConfig.Bind(Config);
|
||||||
// Not a race either: the two Bone Servants, shared by the Skeleton and Skadi, so they
|
// Not a race either: the two Bone Servants, shared by the Skeleton and Skadi, so they
|
||||||
// bind here rather than inside either race's run.
|
// bind here rather than inside either race's run.
|
||||||
ButlerConfig.Bind(Config);
|
ButlerConfig.Bind(Config);
|
||||||
|
|
@ -56,6 +57,8 @@ namespace RacesOfValheim
|
||||||
// Not a race either: the faction truce and the faction merchants, which cut across
|
// Not a race either: the faction truce and the faction merchants, which cut across
|
||||||
// every race at once, so they bind last rather than inside the alphabetical run above.
|
// every race at once, so they bind last rather than inside the alphabetical run above.
|
||||||
FactionsConfig.Bind(Config);
|
FactionsConfig.Bind(Config);
|
||||||
|
// The mod-wide debug switches, at the bottom of the list on purpose.
|
||||||
|
DebugConfig.Bind(Config);
|
||||||
// After every Bind above: tags the gameplay entries for Jotunn's server-to-client sync.
|
// After every Bind above: tags the gameplay entries for Jotunn's server-to-client sync.
|
||||||
ConfigSync.Apply(Config);
|
ConfigSync.Apply(Config);
|
||||||
harmony.PatchAll();
|
harmony.PatchAll();
|
||||||
|
|
@ -75,6 +78,9 @@ namespace RacesOfValheim
|
||||||
PrefabManager.OnVanillaPrefabsAvailable += CreateAllModAssets;
|
PrefabManager.OnVanillaPrefabsAvailable += CreateAllModAssets;
|
||||||
CommandManager.Instance.AddConsoleCommand(new ResetRaceCommand());
|
CommandManager.Instance.AddConsoleCommand(new ResetRaceCommand());
|
||||||
CommandManager.Instance.AddConsoleCommand(new CheckProgressionCommand());
|
CommandManager.Instance.AddConsoleCommand(new CheckProgressionCommand());
|
||||||
|
CommandManager.Instance.AddConsoleCommand(new TrolSoundCommand("rovsnd1", TrolSounds.Death));
|
||||||
|
CommandManager.Instance.AddConsoleCommand(new TrolSoundCommand("rovsnd2", TrolSounds.Building));
|
||||||
|
StartCoroutine(TrolSounds.Load());
|
||||||
CommandManager.Instance.AddConsoleCommand(new IncreaseProgressionCommand());
|
CommandManager.Instance.AddConsoleCommand(new IncreaseProgressionCommand());
|
||||||
CommandManager.Instance.AddConsoleCommand(new ResetProgressionCommand());
|
CommandManager.Instance.AddConsoleCommand(new ResetProgressionCommand());
|
||||||
CommandManager.Instance.AddConsoleCommand(new DumpDvergerCommand());
|
CommandManager.Instance.AddConsoleCommand(new DumpDvergerCommand());
|
||||||
|
|
@ -89,6 +95,7 @@ namespace RacesOfValheim
|
||||||
CommandManager.Instance.AddConsoleCommand(new AlfarEitrCommand());
|
CommandManager.Instance.AddConsoleCommand(new AlfarEitrCommand());
|
||||||
CommandManager.Instance.AddConsoleCommand(new AlfarHpCommand());
|
CommandManager.Instance.AddConsoleCommand(new AlfarHpCommand());
|
||||||
CommandManager.Instance.AddConsoleCommand(new DumpAnimCommand());
|
CommandManager.Instance.AddConsoleCommand(new DumpAnimCommand());
|
||||||
|
CommandManager.Instance.AddConsoleCommand(new TrolPoseCommand());
|
||||||
CommandManager.Instance.AddConsoleCommand(new EvilLaughCommand());
|
CommandManager.Instance.AddConsoleCommand(new EvilLaughCommand());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -305,6 +312,7 @@ namespace RacesOfValheim
|
||||||
AlfarRace.CreateModAssets();
|
AlfarRace.CreateModAssets();
|
||||||
WarVultureItem.Register();
|
WarVultureItem.Register();
|
||||||
TrolsHammerItem.Register();
|
TrolsHammerItem.Register();
|
||||||
|
ShrinkHammerItem.Register();
|
||||||
BoneServant.Register();
|
BoneServant.Register();
|
||||||
}
|
}
|
||||||
// --- RACE SELECTION UI ---
|
// --- RACE SELECTION UI ---
|
||||||
|
|
|
||||||
|
|
@ -53,10 +53,17 @@
|
||||||
<Reference Include="System.Xml" />
|
<Reference Include="System.Xml" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
<!-- Textures painted offline (scripts/paint_cook_cloth.py), carried inside the DLL so a mod
|
||||||
|
manager has no extra folder to flatten. Loaded by name: PieceLook.LoadTexture("CookCloth_d.png"). -->
|
||||||
|
<ItemGroup>
|
||||||
|
<EmbeddedResource Include="Assets\**\*.png" LogicalName="%(Filename)%(Extension)" />
|
||||||
|
<EmbeddedResource Include="Audio\*.ogg" LogicalName="%(Filename)%(Extension)" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="app.config" />
|
<None Include="app.config" />
|
||||||
<None Include="packages.config" />
|
<None Include="packages.config" />
|
||||||
<None Include="README.md" />
|
<None Include="..\README.md" Link="README.md" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|
|
||||||
211
JotunnModStub/ShrinkHammer/BuildScale.cs
Normal file
|
|
@ -0,0 +1,211 @@
|
||||||
|
using BepInEx.Configuration;
|
||||||
|
using HarmonyLib;
|
||||||
|
using TMPro;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace RacesOfValheim
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// What both sizing hammers share: which size the hammer in hand builds at, Alt + scroll to
|
||||||
|
/// change it, the size floating over the ghost, and the "Alt: Size" row in the bottom bar.
|
||||||
|
///
|
||||||
|
/// Trol's Hammer builds 1 to 3 times the vanilla size, the Shrink Hammer a quarter to 1. Each
|
||||||
|
/// keeps its size in its own config entry, and the wheel writes that entry, so Configuration
|
||||||
|
/// Manager and the wheel never disagree. The entries are not synced: each player picks their own.
|
||||||
|
/// Alt is free in build mode: vanilla's own placing modifier ("AltPlace") is Left Shift.
|
||||||
|
/// </summary>
|
||||||
|
public static class BuildScale
|
||||||
|
{
|
||||||
|
public const float Step = 0.05f;
|
||||||
|
|
||||||
|
/// <summary>The config entry behind the hammer in hand, or null for any other tool.</summary>
|
||||||
|
public static ConfigEntry<float> EntryFor(ItemDrop.ItemData item)
|
||||||
|
{
|
||||||
|
if (TrolsHammerItem.IsTrolsHammer(item)) return TrolsHammerConfig.ScaleFactor;
|
||||||
|
if (ShrinkHammerItem.IsShrinkHammer(item)) return ShrinkHammerConfig.ScaleFactor;
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>The multiplier a placement with this item in hand gets: 1 for any other tool.</summary>
|
||||||
|
public static float For(ItemDrop.ItemData item)
|
||||||
|
{
|
||||||
|
if (TrolsHammerItem.IsTrolsHammer(item)) return TrolsHammerConfig.ActiveFactor();
|
||||||
|
if (ShrinkHammerItem.IsShrinkHammer(item)) return ShrinkHammerConfig.ActiveFactor();
|
||||||
|
return 1f;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool AltHeld() => Input.GetKey(KeyCode.LeftAlt) || Input.GetKey(KeyCode.RightAlt);
|
||||||
|
|
||||||
|
/// <summary>Moves the entry by whole steps, kept on the 0.05 grid and inside its range.</summary>
|
||||||
|
public static void Nudge(ConfigEntry<float> entry, int steps)
|
||||||
|
{
|
||||||
|
AcceptableValueRange<float> range = entry.Description.AcceptableValues as AcceptableValueRange<float>;
|
||||||
|
float min = range != null ? range.MinValue : 0.25f, max = range != null ? range.MaxValue : 3f;
|
||||||
|
float value = Mathf.Round((entry.Value + steps * Step) / Step) * Step;
|
||||||
|
entry.Value = Mathf.Clamp(value, min, max);
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- the size over the ghost ---
|
||||||
|
|
||||||
|
private static GameObject s_labelled;
|
||||||
|
private static float s_shown;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The size in Valheim's own floating NPC text, with one of the two hammers in hand:
|
||||||
|
/// - over the ghost, while the hammer's size differs from its default (1.2 for Trol's
|
||||||
|
/// Hammer, 1 for the Shrink Hammer);
|
||||||
|
/// - with the repair tool selected, over the piece aimed at, always: the size it was built
|
||||||
|
/// at, 1 for a piece no sizing hammer built.
|
||||||
|
/// The text has no timeout, so it is set again only when its piece or the size changes:
|
||||||
|
/// setting it replays its fade-in.
|
||||||
|
/// </summary>
|
||||||
|
public static void UpdateLabel(Player player, GameObject ghost)
|
||||||
|
{
|
||||||
|
if (Chat.instance == null) return;
|
||||||
|
|
||||||
|
ConfigEntry<float> entry = player != null && player.InPlaceMode() ? EntryFor(player.RightItem) : null;
|
||||||
|
if (entry == null)
|
||||||
|
{
|
||||||
|
ClearLabel();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Piece tool = player.GetSelectedPiece();
|
||||||
|
if (tool != null && tool.m_repairPiece)
|
||||||
|
{
|
||||||
|
Piece aimed = player.GetHoveringPiece();
|
||||||
|
if (aimed != null) Show(aimed.gameObject, BuiltSize(aimed));
|
||||||
|
else ClearLabel();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
float value = For(player.RightItem);
|
||||||
|
if (ghost != null && ghost.activeInHierarchy && !Mathf.Approximately(value, (float)entry.DefaultValue))
|
||||||
|
Show(ghost, value);
|
||||||
|
else
|
||||||
|
ClearLabel();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>The size a placed piece was built at, from its ZDO; 1 when no sizing hammer built it.</summary>
|
||||||
|
private static float BuiltSize(Piece piece)
|
||||||
|
{
|
||||||
|
ZDO zdo = piece.GetComponent<ZNetView>()?.GetZDO();
|
||||||
|
float saved = zdo != null ? zdo.GetFloat(TrolsHammerScaling.ScaleKey, 0f) : 0f;
|
||||||
|
return saved > 0f ? saved : 1f;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void Show(GameObject target, float value)
|
||||||
|
{
|
||||||
|
if (target == s_labelled && Mathf.Approximately(value, s_shown)) return;
|
||||||
|
|
||||||
|
ClearLabel();
|
||||||
|
Chat.instance.SetNpcText(target, Vector3.up * (TopOf(target) + 0.3f), 30f, 0f, "",
|
||||||
|
ModText.Get("rov_msg_build_scale", value.ToString("0.00")), false);
|
||||||
|
s_labelled = target;
|
||||||
|
s_shown = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void ClearLabel()
|
||||||
|
{
|
||||||
|
if (s_labelled != null && Chat.instance != null) Chat.instance.ClearNpcText(s_labelled);
|
||||||
|
s_labelled = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>How far above its pivot the ghost reaches, from its renderers.</summary>
|
||||||
|
private static float TopOf(GameObject ghost)
|
||||||
|
{
|
||||||
|
float top = 0.5f;
|
||||||
|
foreach (Renderer renderer in ghost.GetComponentsInChildren<Renderer>())
|
||||||
|
top = Mathf.Max(top, renderer.bounds.max.y - ghost.transform.position.y);
|
||||||
|
return top;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Alt + scroll in build mode. Vanilla turns the piece with the same wheel in the same method,
|
||||||
|
/// whatever key is held, so the prefix reads the wheel for the size and the postfix puts the
|
||||||
|
/// rotation back as it was.
|
||||||
|
/// </summary>
|
||||||
|
[HarmonyPatch(typeof(Player), "UpdatePlacement")]
|
||||||
|
public static class BuildScaleScrollPatch
|
||||||
|
{
|
||||||
|
private static float s_scroll;
|
||||||
|
|
||||||
|
private static void Prefix(Player __instance, bool takeInput, int ___m_placeRotation, out int __state)
|
||||||
|
{
|
||||||
|
__state = ___m_placeRotation;
|
||||||
|
if (!takeInput || __instance != Player.m_localPlayer || !__instance.InPlaceMode()) return;
|
||||||
|
if (!BuildScale.AltHeld()) return;
|
||||||
|
ConfigEntry<float> entry = BuildScale.EntryFor(__instance.RightItem);
|
||||||
|
if (entry == null) return;
|
||||||
|
|
||||||
|
s_scroll += ZInput.GetMouseScrollWheel();
|
||||||
|
if (s_scroll > __instance.m_scrollAmountThreshold) { s_scroll = 0f; BuildScale.Nudge(entry, 1); }
|
||||||
|
if (s_scroll < -__instance.m_scrollAmountThreshold) { s_scroll = 0f; BuildScale.Nudge(entry, -1); }
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void Postfix(Player __instance, int __state, ref int ___m_placeRotation,
|
||||||
|
ref float ___m_scrollCurrAmount, GameObject ___m_placementGhost)
|
||||||
|
{
|
||||||
|
if (__instance != Player.m_localPlayer) return;
|
||||||
|
|
||||||
|
if (BuildScale.AltHeld() && BuildScale.EntryFor(__instance.RightItem) != null)
|
||||||
|
{
|
||||||
|
___m_placeRotation = __state;
|
||||||
|
___m_scrollCurrAmount = 0f;
|
||||||
|
}
|
||||||
|
BuildScale.UpdateLabel(__instance, ___m_placementGhost);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The "Alt: Size" row in the build hints, next to vanilla's "Rotate": a copy of that row (the
|
||||||
|
/// wheel icon and its text), shown only while one of the two hammers is in hand. Added beside the
|
||||||
|
/// vanilla rows rather than through Jotunn's key hints, which replace the whole bar for an item.
|
||||||
|
/// </summary>
|
||||||
|
[HarmonyPatch(typeof(KeyHints), "UpdateHints")]
|
||||||
|
public static class BuildScaleKeyHintPatch
|
||||||
|
{
|
||||||
|
private static GameObject s_row;
|
||||||
|
private static bool s_failed;
|
||||||
|
|
||||||
|
private static void Postfix(KeyHints __instance)
|
||||||
|
{
|
||||||
|
if (s_row == null && !s_failed) s_row = MakeRow(__instance);
|
||||||
|
if (s_row == null) return;
|
||||||
|
|
||||||
|
Player player = Player.m_localPlayer;
|
||||||
|
bool show = player != null && BuildScale.EntryFor(player.RightItem) != null;
|
||||||
|
if (s_row.activeSelf != show) s_row.SetActive(show);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static GameObject MakeRow(KeyHints hints)
|
||||||
|
{
|
||||||
|
Transform rotate = hints.m_buildHints != null ? FindDeep(hints.m_buildHints.transform, "rotate") : null;
|
||||||
|
TMP_Text source = rotate != null ? rotate.Find("Text")?.GetComponent<TMP_Text>() : null;
|
||||||
|
if (source == null)
|
||||||
|
{
|
||||||
|
s_failed = true;
|
||||||
|
Jotunn.Logger.LogWarning("[BuildScale] No rotate row in the build hints; the Alt: Size hint is not shown.");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
GameObject row = Object.Instantiate(rotate.gameObject, rotate.parent, false);
|
||||||
|
row.name = "RoV_scale";
|
||||||
|
row.transform.SetSiblingIndex(rotate.GetSiblingIndex() + 1);
|
||||||
|
row.transform.Find("Text").GetComponent<TMP_Text>().text = ModText.Get("rov_hint_build_scale");
|
||||||
|
return row;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Transform FindDeep(Transform parent, string name)
|
||||||
|
{
|
||||||
|
foreach (Transform child in parent)
|
||||||
|
{
|
||||||
|
if (child.name == name) return child;
|
||||||
|
Transform found = FindDeep(child, name);
|
||||||
|
if (found != null) return found;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
33
JotunnModStub/ShrinkHammer/ShrinkHammerConfig.cs
Normal file
|
|
@ -0,0 +1,33 @@
|
||||||
|
using BepInEx.Configuration;
|
||||||
|
|
||||||
|
namespace RacesOfValheim
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The Shrink Hammer's one number: the size it builds at, from a quarter of the vanilla piece up
|
||||||
|
/// to the vanilla size. Bigger than vanilla is Trol's Hammer's job. Alt + scroll with the hammer
|
||||||
|
/// in hand writes this same entry (BuildScale), so the slider in Configuration Manager and the
|
||||||
|
/// wheel always agree, and the size survives a restart.
|
||||||
|
/// </summary>
|
||||||
|
public static class ShrinkHammerConfig
|
||||||
|
{
|
||||||
|
public static ConfigEntry<float> ScaleFactor;
|
||||||
|
|
||||||
|
public static void Bind(ConfigFile config)
|
||||||
|
{
|
||||||
|
ScaleFactor = config.Bind("Shrink Hammer", "Scale factor", 1f,
|
||||||
|
new ConfigDescription("The size of the pieces the Shrink Hammer builds, against the " +
|
||||||
|
"vanilla piece: 1 is vanilla size, 0.25 a quarter. Hold Alt and " +
|
||||||
|
"scroll in build mode to change it in steps of 0.05. Cost and " +
|
||||||
|
"drop never change. A ship keeps its physics at any size.",
|
||||||
|
new AcceptableValueRange<float>(0.25f, 1f)));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>The multiplier a new placement should use; 1 for a value typed into the .cfg
|
||||||
|
/// file that would make a piece too small to see, hit or remove.</summary>
|
||||||
|
public static float ActiveFactor()
|
||||||
|
{
|
||||||
|
if (ScaleFactor == null) return 1f;
|
||||||
|
return ScaleFactor.Value > 0.01f ? ScaleFactor.Value : 1f;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
77
JotunnModStub/ShrinkHammer/ShrinkHammerItem.cs
Normal file
|
|
@ -0,0 +1,77 @@
|
||||||
|
using Jotunn.Configs;
|
||||||
|
using Jotunn.Entities;
|
||||||
|
using Jotunn.Managers;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace RacesOfValheim
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The Shrink Hammer: the builder's hammer for small work, down to a quarter of the vanilla size.
|
||||||
|
/// Any race can craft it. Built the same way as <see cref="TrolsHammerItem"/>: a clone of the
|
||||||
|
/// vanilla Hammer that keeps the vanilla piece table, so every piece, including those other mods
|
||||||
|
/// add, is in its menu at the same cost. The size lives on the placement (TrolsHammerPatches,
|
||||||
|
/// BuildScale), never on the piece prefabs.
|
||||||
|
/// </summary>
|
||||||
|
public static class ShrinkHammerItem
|
||||||
|
{
|
||||||
|
public const string PrefabName = "ShrinkHammer";
|
||||||
|
public const string DisplayName = "$rov_item_shrinkhammer_name";
|
||||||
|
|
||||||
|
private const string SourcePrefab = "Hammer";
|
||||||
|
private const string Label = "ShrinkHammer";
|
||||||
|
|
||||||
|
public static void Register()
|
||||||
|
{
|
||||||
|
GameObject prefab = PrefabManager.Instance.CreateClonedPrefab(PrefabName, SourcePrefab);
|
||||||
|
ItemDrop drop = prefab != null ? prefab.GetComponent<ItemDrop>() : null;
|
||||||
|
if (drop == null || drop.m_itemData == null || drop.m_itemData.m_shared == null)
|
||||||
|
{
|
||||||
|
Jotunn.Logger.LogWarning($"[{Label}] Could not clone {SourcePrefab}; {DisplayName} not registered.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ItemDrop.ItemData.SharedData shared = drop.m_itemData.m_shared;
|
||||||
|
shared.m_name = DisplayName;
|
||||||
|
shared.m_description = "$rov_item_shrinkhammer_desc";
|
||||||
|
Sprite icon = HammerIcon.Load("ShrinkHammer_icon.png");
|
||||||
|
if (icon != null) shared.m_icons = new[] { icon };
|
||||||
|
|
||||||
|
ItemManager.Instance.AddItem(new CustomItem(prefab, fixReference: false));
|
||||||
|
ItemManager.Instance.AddRecipe(new CustomRecipe(new RecipeConfig
|
||||||
|
{
|
||||||
|
Item = PrefabName,
|
||||||
|
Amount = 1,
|
||||||
|
CraftingStation = CraftingStations.Workbench,
|
||||||
|
MinStationLevel = 1,
|
||||||
|
Requirements = new[]
|
||||||
|
{
|
||||||
|
new RequirementConfig("FineWood", 2, 0, true),
|
||||||
|
new RequirementConfig("Resin", 2, 0, true),
|
||||||
|
},
|
||||||
|
}));
|
||||||
|
|
||||||
|
Jotunn.Logger.LogInfo($"[{Label}] {DisplayName} registered on the vanilla hammer's piece table.");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>Whether an item in hand is this hammer; the display name is the fallback for an
|
||||||
|
/// ItemData built before ObjectDB finished, as in TrolsHammerItem.</summary>
|
||||||
|
public static bool IsShrinkHammer(ItemDrop.ItemData item)
|
||||||
|
{
|
||||||
|
if (item == null) return false;
|
||||||
|
if (item.m_dropPrefab != null) return item.m_dropPrefab.name == PrefabName;
|
||||||
|
return item.m_shared != null && item.m_shared.m_name == DisplayName;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>The two hammers' own icons, painted offline (scripts/paint_hammer_icons.py) and
|
||||||
|
/// embedded in the DLL.</summary>
|
||||||
|
internal static class HammerIcon
|
||||||
|
{
|
||||||
|
public static Sprite Load(string resource)
|
||||||
|
{
|
||||||
|
Texture2D texture = PieceLook.LoadTexture(resource);
|
||||||
|
if (texture == null) return null;
|
||||||
|
return Sprite.Create(texture, new Rect(0f, 0f, texture.width, texture.height), new Vector2(0.5f, 0.5f));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -4,10 +4,10 @@ using Jotunn.Managers;
|
||||||
|
|
||||||
namespace RacesOfValheim
|
namespace RacesOfValheim
|
||||||
{
|
{
|
||||||
public class DrakeFormBehavior : MonoBehaviour
|
public class DrakeFormBehavior : MonoBehaviour, IDirectedFlyer
|
||||||
{
|
{
|
||||||
// Single active instance, read by SkadiDirectedFlightPatch to feed a
|
// Single active instance, read by the Skadi patches that care about the drake itself
|
||||||
// look-direction-based m_moveDir into Character.UpdateFlying every frame.
|
// (breath facing, attacks). Flight reads it through DirectedFlight.Active instead.
|
||||||
public static DrakeFormBehavior Active { get; private set; }
|
public static DrakeFormBehavior Active { get; private set; }
|
||||||
|
|
||||||
private Animator anim;
|
private Animator anim;
|
||||||
|
|
@ -41,9 +41,41 @@ namespace RacesOfValheim
|
||||||
if (nview != null && nview.IsValid()) nview.GetZDO().Set(FlyingKey, value);
|
if (nview != null && nview.IsValid()) nview.GetZDO().Set(FlyingKey, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Time.time of the last powered/grounded moment. SkadiDirectedFlightPatch holds the form
|
// Time.time of the last powered/grounded moment. DirectedFlightPatch holds the form
|
||||||
// level for a short window past this before letting it start sinking.
|
// level for a short window past this before letting it start sinking.
|
||||||
public float LastPoweredTime;
|
public float LastPoweredTime { get; set; }
|
||||||
|
|
||||||
|
// This form's numbers for DirectedFlightPatch. The Drake's base flight defaults to free on
|
||||||
|
// purpose - it arrives at the Elder, long before the player has the stamina pool to pay
|
||||||
|
// for simply staying airborne - so only its sprint costs anything. The Moder pays for
|
||||||
|
// every beat. The Fader never flies, so it falls back on the Drake's set unread.
|
||||||
|
private SkadiConfig.FormFlight Flight =>
|
||||||
|
formRules != null && formRules.Form == SkadiProgression.FormType.Moder ? SkadiConfig.ModerFlight : SkadiConfig.DrakeFlight;
|
||||||
|
|
||||||
|
public float TurnSpeed => Flight.TurnSpeed.Value;
|
||||||
|
public float GlideSpeed => Flight.GlideSpeed.Value;
|
||||||
|
public float BoostSpeed => Flight.BoostSpeed.Value;
|
||||||
|
public float SprintSpeed => Flight.SprintSpeed.Value;
|
||||||
|
public float ReverseSpeed => Flight.ReverseSpeed.Value;
|
||||||
|
// Climbing out of water is deliberately slower than a powered climb in open air - the
|
||||||
|
// wings are dragging themselves free, not racing.
|
||||||
|
public float LiftoffSpeed => Flight.LiftoffSpeed.Value;
|
||||||
|
public float HoverSeconds => Flight.HoverSeconds.Value;
|
||||||
|
public float PoweredStaminaPerSecond => Flight.PoweredStaminaPerSecond.Value * EncumberedCostFactor();
|
||||||
|
public float SprintStaminaPerSecond => Flight.SprintStaminaPerSecond.Value * EncumberedCostFactor();
|
||||||
|
public bool CanPower => !(IsEncumbered() && TooHeavyToFly);
|
||||||
|
|
||||||
|
private bool TooHeavyToFly => Flight.Encumbered.Value == AswidConfig.EncumberedMode.Blocked;
|
||||||
|
|
||||||
|
private static bool IsEncumbered()
|
||||||
|
{
|
||||||
|
return Player.m_localPlayer != null && Player.m_localPlayer.IsEncumbered();
|
||||||
|
}
|
||||||
|
|
||||||
|
private float EncumberedCostFactor()
|
||||||
|
{
|
||||||
|
return IsEncumbered() ? 1f + Flight.EncumberedExtraCost.Value : 1f;
|
||||||
|
}
|
||||||
|
|
||||||
private SkadiProgression.FormRules formRules;
|
private SkadiProgression.FormRules formRules;
|
||||||
|
|
||||||
|
|
@ -97,6 +129,7 @@ namespace RacesOfValheim
|
||||||
private void Start()
|
private void Start()
|
||||||
{
|
{
|
||||||
Active = this;
|
Active = this;
|
||||||
|
DirectedFlight.Register(this);
|
||||||
anim = GetComponentInChildren<Animator>();
|
anim = GetComponentInChildren<Animator>();
|
||||||
|
|
||||||
if (Player.m_localPlayer != null)
|
if (Player.m_localPlayer != null)
|
||||||
|
|
@ -154,7 +187,11 @@ namespace RacesOfValheim
|
||||||
(SkadiConfig.FlightToggleKey.Value.IsDownIgnoringHeldKeys() || RaceInput.PadAttackDown(1)) &&
|
(SkadiConfig.FlightToggleKey.Value.IsDownIgnoringHeldKeys() || RaceInput.PadAttackDown(1)) &&
|
||||||
formRules != null && formRules.Form != SkadiProgression.FormType.SkeletonDragon)
|
formRules != null && formRules.Form != SkadiProgression.FormType.SkeletonDragon)
|
||||||
{
|
{
|
||||||
if (!isFlying && !isLanding)
|
if (!isFlying && !isLanding && IsEncumbered() && TooHeavyToFly)
|
||||||
|
{
|
||||||
|
Player.m_localPlayer.Message(MessageHud.MessageType.Center, ModText.Get("rov_msg_skadi_too_heavy_to_fly"));
|
||||||
|
}
|
||||||
|
else if (!isFlying && !isLanding)
|
||||||
{
|
{
|
||||||
isFlying = true;
|
isFlying = true;
|
||||||
LastPoweredTime = Time.time;
|
LastPoweredTime = Time.time;
|
||||||
|
|
@ -274,6 +311,29 @@ namespace RacesOfValheim
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// How many hit events the form's clips have sent: the dragon's own "Hit" event, which
|
||||||
|
/// CharacterAnimEvent hands to the player's OnAttackTrigger and SkadiBlockAttackTriggerPatch
|
||||||
|
/// counts here instead of letting it through. FenrirForms.AttackEvents, the same idea.
|
||||||
|
/// </summary>
|
||||||
|
public static int AttackEvents { get; private set; }
|
||||||
|
|
||||||
|
public static void NotifyAttackTrigger() => AttackEvents++;
|
||||||
|
|
||||||
|
// Longest a melee waits for its Hit event before landing anyway, from the trigger. The
|
||||||
|
// slowest blow is the Moder's claw at 2.0 s of 3.75 s; a clip that never sends one must
|
||||||
|
// not leave the swing hitting nothing.
|
||||||
|
private const float HitEventTimeout = 3f;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Waits for the clip's own blow. A fixed 0.5 s used to land every melee early, read off the
|
||||||
|
/// game's clips: Moder bite 0.60 s and claws 2.0 s, Fader bite 1.27 s, claws 1.24 s, spin 1.30 s.
|
||||||
|
/// </summary>
|
||||||
|
private IEnumerator WaitForHit(int baseline, float started)
|
||||||
|
{
|
||||||
|
while (AttackEvents == baseline && Time.time - started < HitEventTimeout) yield return null;
|
||||||
|
}
|
||||||
|
|
||||||
private IEnumerator PerformAttackCoroutine(int button)
|
private IEnumerator PerformAttackCoroutine(int button)
|
||||||
{
|
{
|
||||||
lastAttackTime = Time.time;
|
lastAttackTime = Time.time;
|
||||||
|
|
@ -372,13 +432,18 @@ namespace RacesOfValheim
|
||||||
breathingUntil = Time.time + projDelay + projCount * 0.05f + 0.5f;
|
breathingUntil = Time.time + projDelay + projCount * 0.05f + 0.5f;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int hitBaseline = AttackEvents;
|
||||||
|
float triggeredAt = Time.time;
|
||||||
SetAttackTrigger(attackTrigger);
|
SetAttackTrigger(attackTrigger);
|
||||||
|
|
||||||
yield return new WaitForSeconds(projDelay);
|
|
||||||
|
|
||||||
if (isMelee)
|
if (isMelee)
|
||||||
{
|
{
|
||||||
ExecuteMeleeDamage(MODER_MELEE_DAMAGE, MELEE_RADIUS);
|
yield return WaitForHit(hitBaseline, triggeredAt);
|
||||||
|
ExecuteMeleeDamage(MODER_MELEE_DAMAGE, MELEE_RADIUS, MeleeWeapon(attackTrigger));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
yield return new WaitForSeconds(projDelay);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isMelee && projName != null)
|
if (!isMelee && projName != null)
|
||||||
|
|
@ -478,13 +543,18 @@ namespace RacesOfValheim
|
||||||
breathingUntil = Time.time + projDelay + projCount * 0.05f + 0.5f;
|
breathingUntil = Time.time + projDelay + projCount * 0.05f + 0.5f;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int hitBaseline = AttackEvents;
|
||||||
|
float triggeredAt = Time.time;
|
||||||
SetAttackTrigger(attackTrigger);
|
SetAttackTrigger(attackTrigger);
|
||||||
|
|
||||||
yield return new WaitForSeconds(projDelay);
|
|
||||||
|
|
||||||
if (isMelee)
|
if (isMelee)
|
||||||
{
|
{
|
||||||
ExecuteMeleeDamage(meleeDamage, meleeRadius);
|
yield return WaitForHit(hitBaseline, triggeredAt);
|
||||||
|
ExecuteMeleeDamage(meleeDamage, meleeRadius, MeleeWeapon(attackTrigger));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
yield return new WaitForSeconds(projDelay);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isMelee && projName != null)
|
if (!isMelee && projName != null)
|
||||||
|
|
@ -546,7 +616,28 @@ namespace RacesOfValheim
|
||||||
// The dragon forms never go through Humanoid.StartAttack - SkadiAttackPatch blocks it, and
|
// The dragon forms never go through Humanoid.StartAttack - SkadiAttackPatch blocks it, and
|
||||||
// they carry no weapon - so the bite, claw and spin animations landed no damage at all and
|
// they carry no weapon - so the bite, claw and spin animations landed no damage at all and
|
||||||
// simply burned eitr. Sweep for targets the way FenrirBehaviors does for its claws.
|
// simply burned eitr. Sweep for targets the way FenrirBehaviors does for its claws.
|
||||||
private void ExecuteMeleeDamage(float baseDamage, float radius)
|
private string FormLabel => formRules != null ? formRules.Form.ToString() : "Skadi form";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The real creature's attack item behind each melee trigger, for its impact sound. The
|
||||||
|
/// Fader's spin has no item of its own in the game's manifest, so it borrows the claw's.
|
||||||
|
/// </summary>
|
||||||
|
private string MeleeWeapon(string trigger)
|
||||||
|
{
|
||||||
|
bool fader = formRules != null && formRules.Form == SkadiProgression.FormType.SkeletonDragon;
|
||||||
|
switch (trigger)
|
||||||
|
{
|
||||||
|
case "attack_bite": return fader ? "Fader_Bite" : "dragon_bite";
|
||||||
|
case "attack_claw_left": return "dragon_claw_left";
|
||||||
|
case "attack_claw_right": return "dragon_claw_right";
|
||||||
|
case "attack_ClawL": return "Fader_Claw_Left";
|
||||||
|
case "attack_ClawR": return "Fader_Claw_Right";
|
||||||
|
case "attack_Spin": return "Fader_Claw_Left";
|
||||||
|
default: return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ExecuteMeleeDamage(float baseDamage, float radius, string weapon)
|
||||||
{
|
{
|
||||||
if (Player.m_localPlayer == null) return;
|
if (Player.m_localPlayer == null) return;
|
||||||
|
|
||||||
|
|
@ -561,7 +652,10 @@ namespace RacesOfValheim
|
||||||
|
|
||||||
int layerMask = LayerMask.GetMask("Default", "static_solid", "Default_small", "piece", "piece_nonsolid", "terrain", "character", "character_net", "character_ghost", "hitbox", "character_noenv", "vehicle");
|
int layerMask = LayerMask.GetMask("Default", "static_solid", "Default_small", "piece", "piece_nonsolid", "terrain", "character", "character_net", "character_ghost", "hitbox", "character_noenv", "vehicle");
|
||||||
Collider[] hits = Physics.OverlapSphere(attackPoint, radius, layerMask);
|
Collider[] hits = Physics.OverlapSphere(attackPoint, radius, layerMask);
|
||||||
|
FormMelee.LogSwing(FormLabel, hits.Length);
|
||||||
|
ItemDrop.ItemData.SharedData shared = FormMelee.CreatureWeapon(weapon);
|
||||||
System.Collections.Generic.HashSet<GameObject> hitObjects = new System.Collections.Generic.HashSet<GameObject>();
|
System.Collections.Generic.HashSet<GameObject> hitObjects = new System.Collections.Generic.HashSet<GameObject>();
|
||||||
|
bool hitCreature = false;
|
||||||
|
|
||||||
foreach (Collider hit in hits)
|
foreach (Collider hit in hits)
|
||||||
{
|
{
|
||||||
|
|
@ -575,18 +669,29 @@ namespace RacesOfValheim
|
||||||
if (characterTarget != null && characterTarget == Player.m_localPlayer) continue;
|
if (characterTarget != null && characterTarget == Player.m_localPlayer) continue;
|
||||||
|
|
||||||
GameObject targetObj = (target as MonoBehaviour)?.gameObject;
|
GameObject targetObj = (target as MonoBehaviour)?.gameObject;
|
||||||
if (targetObj != null)
|
// Marked only once it is hit, further down: marking it here let the first collider
|
||||||
{
|
// found (a limb outside the arc) rule out a body squarely in the swing.
|
||||||
if (hitObjects.Contains(targetObj)) continue;
|
if (targetObj != null && hitObjects.Contains(targetObj)) continue;
|
||||||
hitObjects.Add(targetObj);
|
|
||||||
}
|
|
||||||
|
|
||||||
Vector3 targetCenter = hit.bounds.center;
|
Vector3 targetCenter = hit.bounds.center;
|
||||||
Vector3 dirToTarget = (targetCenter - playerPos).normalized;
|
Vector3 dirToTarget = (targetCenter - playerPos).normalized;
|
||||||
if (!fullCircle && Vector3.Angle(forward, dirToTarget) >= 70f) continue;
|
float angle = Vector3.Angle(forward, dirToTarget);
|
||||||
|
if (!fullCircle && angle >= 70f)
|
||||||
|
{
|
||||||
|
FormMelee.LogMiss(FormLabel, hit, $"outside the swing arc ({angle:0} deg)");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// FormMelee.CanReach, not a bare Linecast. The Linecast tested the piece layer and
|
||||||
|
// counted the target's own collider as cover, so anything living on that layer
|
||||||
|
// could never be hit: the T.W.I.G. training dummy is a Humanoid whose only collider
|
||||||
|
// is on "piece". Wildlife sits on "character" and was never affected.
|
||||||
Vector3 eyePos = playerPos + Vector3.up * 1.5f;
|
Vector3 eyePos = playerPos + Vector3.up * 1.5f;
|
||||||
if (Physics.Linecast(eyePos, targetCenter, out RaycastHit rayHit, LayerMask.GetMask("Default", "static_solid", "terrain", "piece"))) continue;
|
if (!FormMelee.CanReach(eyePos, attackPoint, hit, target, out string cover))
|
||||||
|
{
|
||||||
|
FormMelee.LogMiss(FormLabel, hit, "no clear line, blocked by '" + cover + "'");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
HitData hitData = new HitData();
|
HitData hitData = new HitData();
|
||||||
// Frost-flavoured maul; SkadiDamagePatch tops this up with the per-tier frost bonus.
|
// Frost-flavoured maul; SkadiDamagePatch tops this up with the per-tier frost bonus.
|
||||||
|
|
@ -602,13 +707,21 @@ namespace RacesOfValheim
|
||||||
hitData.m_toolTier = 0;
|
hitData.m_toolTier = 0;
|
||||||
hitData.SetAttacker(Player.m_localPlayer);
|
hitData.SetAttacker(Player.m_localPlayer);
|
||||||
|
|
||||||
|
if (targetObj != null) hitObjects.Add(targetObj);
|
||||||
|
FormMelee.LogHit(FormLabel, target, totalDamage);
|
||||||
target.Damage(hitData);
|
target.Damage(hitData);
|
||||||
|
FormMelee.GrantAdrenaline(target);
|
||||||
|
shared?.m_hitEffect.Create(targetCenter, Quaternion.identity);
|
||||||
|
if (characterTarget != null) hitCreature = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (hitCreature) FormMelee.RaiseSkill(Skills.SkillType.Unarmed);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnDestroy()
|
private void OnDestroy()
|
||||||
{
|
{
|
||||||
if (Active == this) Active = null;
|
if (Active == this) Active = null;
|
||||||
|
DirectedFlight.Unregister(this);
|
||||||
if (Player.m_localPlayer != null)
|
if (Player.m_localPlayer != null)
|
||||||
{
|
{
|
||||||
SetFlying(false);
|
SetFlying(false);
|
||||||
|
|
|
||||||
|
|
@ -69,15 +69,38 @@ namespace RacesOfValheim
|
||||||
public static ConfigEntry<float> FaderSpinDamage;
|
public static ConfigEntry<float> FaderSpinDamage;
|
||||||
public static ConfigEntry<float> FaderSpinRadius;
|
public static ConfigEntry<float> FaderSpinRadius;
|
||||||
|
|
||||||
// ─── Directed flight (Drake/Moder) ────────────────────────────────────
|
// ─── Dragon forms: flight and timing, one set per form ───────────────────
|
||||||
public static ConfigEntry<float> FlightTurnSpeed;
|
// One section for all three, as Dissolution asked for the bat's knobs on each form: the
|
||||||
public static ConfigEntry<float> FlightGlideSpeed;
|
// keys carry the form's name and an Order, so Configuration Manager lists Drake, then
|
||||||
public static ConfigEntry<float> FlightBoostSpeed;
|
// Moder, then Fader instead of mixing them alphabetically.
|
||||||
public static ConfigEntry<float> FlightSprintSpeed;
|
public class FormFlight
|
||||||
public static ConfigEntry<float> FlightReverseSpeed;
|
{
|
||||||
public static ConfigEntry<float> FlightLiftoffSpeed;
|
public ConfigEntry<float> TurnSpeed;
|
||||||
public static ConfigEntry<float> FlightHoverSeconds;
|
public ConfigEntry<float> GlideSpeed;
|
||||||
public static ConfigEntry<float> FlightSprintStaminaPerSecond;
|
public ConfigEntry<float> BoostSpeed;
|
||||||
|
public ConfigEntry<float> SprintSpeed;
|
||||||
|
public ConfigEntry<float> ReverseSpeed;
|
||||||
|
public ConfigEntry<float> LiftoffSpeed;
|
||||||
|
public ConfigEntry<float> HoverSeconds;
|
||||||
|
public ConfigEntry<float> PoweredStaminaPerSecond;
|
||||||
|
public ConfigEntry<float> SprintStaminaPerSecond;
|
||||||
|
public ConfigEntry<AswidConfig.EncumberedMode> Encumbered;
|
||||||
|
public ConfigEntry<float> EncumberedExtraCost;
|
||||||
|
}
|
||||||
|
|
||||||
|
public class FormTiming
|
||||||
|
{
|
||||||
|
// -1 keeps the boss-tier table in SkadiProgression, so an untouched .cfg plays as before.
|
||||||
|
public ConfigEntry<float> MaxDuration;
|
||||||
|
public ConfigEntry<float> DurationPerState;
|
||||||
|
public ConfigEntry<float> Cooldown;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static FormFlight DrakeFlight;
|
||||||
|
public static FormFlight ModerFlight;
|
||||||
|
public static FormTiming DrakeTiming;
|
||||||
|
public static FormTiming ModerTiming;
|
||||||
|
public static FormTiming FaderTiming;
|
||||||
|
|
||||||
public static void Bind(ConfigFile config)
|
public static void Bind(ConfigFile config)
|
||||||
{
|
{
|
||||||
|
|
@ -164,23 +187,69 @@ namespace RacesOfValheim
|
||||||
FaderSpinRadius = config.Bind(attacks, "Fader Spin Radius", 5f,
|
FaderSpinRadius = config.Bind(attacks, "Fader Spin Radius", 5f,
|
||||||
new ConfigDescription("Hit-sweep radius for the Skeleton Dragon's spin attack.", new AcceptableValueRange<float>(1f, 15f)));
|
new ConfigDescription("Hit-sweep radius for the Skeleton Dragon's spin attack.", new AcceptableValueRange<float>(1f, 15f)));
|
||||||
|
|
||||||
const string flight = "Skadi - Directed Flight";
|
// Was "Skadi - Directed Flight", one set of numbers for both flying forms. The Drake is
|
||||||
FlightTurnSpeed = config.Bind(flight, "Turn Speed", 120f,
|
// the scout: quick, nimble, free to fly, grounded by a heavy pack. The Moder is the
|
||||||
new ConfigDescription("Degrees per second the dragon form turns to face its heading.", new AcceptableValueRange<float>(10f, 360f)));
|
// freighter: slow to turn and paying for every beat, but it lifts what the Drake cannot.
|
||||||
FlightGlideSpeed = config.Bind(flight, "Glide Speed", 5f,
|
const string forms = "Skadi - Dragon Forms";
|
||||||
new ConfigDescription("Speed while gliding unpowered (no W/S held).", new AcceptableValueRange<float>(0f, 30f)));
|
int order = 1000;
|
||||||
FlightBoostSpeed = config.Bind(flight, "Boost Speed", 12f,
|
DrakeFlight = BindFlight(config, forms, "Drake", ref order,
|
||||||
new ConfigDescription("Speed while holding W without sprinting.", new AcceptableValueRange<float>(0f, 50f)));
|
turn: 180f, glide: 6f, boost: 14f, sprint: 26f, reverse: 8f, liftoff: 9f, hover: 3f,
|
||||||
FlightSprintSpeed = config.Bind(flight, "Sprint Speed", 22f,
|
powered: 0f, sprintCost: 10f, encumbered: AswidConfig.EncumberedMode.Blocked, extraCost: 0.25f);
|
||||||
new ConfigDescription("Speed while holding W and Shift, stamina permitting.", new AcceptableValueRange<float>(0f, 60f)));
|
DrakeTiming = BindTiming(config, forms, "Drake", ref order);
|
||||||
FlightReverseSpeed = config.Bind(flight, "Reverse Speed", 7f,
|
ModerFlight = BindFlight(config, forms, "Moder", ref order,
|
||||||
new ConfigDescription("Speed while beating backwards (S).", new AcceptableValueRange<float>(0f, 30f)));
|
turn: 80f, glide: 5f, boost: 10f, sprint: 18f, reverse: 6f, liftoff: 9f, hover: 8f,
|
||||||
FlightLiftoffSpeed = config.Bind(flight, "Liftoff Speed", 9f,
|
powered: 3f, sprintCost: 15f, encumbered: AswidConfig.EncumberedMode.Allowed, extraCost: 0.25f);
|
||||||
new ConfigDescription("Climb speed while clawing out of water.", new AcceptableValueRange<float>(0f, 30f)));
|
ModerTiming = BindTiming(config, forms, "Moder", ref order);
|
||||||
FlightHoverSeconds = config.Bind(flight, "Hover Seconds", 5f,
|
FaderTiming = BindTiming(config, forms, "Fader", ref order);
|
||||||
new ConfigDescription("How long level flight holds altitude after the last powered input before it starts to sink.", new AcceptableValueRange<float>(0f, 30f)));
|
}
|
||||||
FlightSprintStaminaPerSecond = config.Bind(flight, "Sprint Stamina Per Second", 15f,
|
|
||||||
new ConfigDescription("Stamina drained per second while the sprint speed is actually granted.", new AcceptableValueRange<float>(0f, 60f)));
|
private static FormFlight BindFlight(ConfigFile config, string section, string form, ref int order,
|
||||||
|
float turn, float glide, float boost, float sprint, float reverse, float liftoff, float hover,
|
||||||
|
float powered, float sprintCost, AswidConfig.EncumberedMode encumbered, float extraCost)
|
||||||
|
{
|
||||||
|
return new FormFlight
|
||||||
|
{
|
||||||
|
TurnSpeed = config.Bind(section, $"{form} Turn Speed", turn,
|
||||||
|
OrderedDesc($"Degrees per second the {form} turns towards where you aim.", new AcceptableValueRange<float>(10f, 360f), order--)),
|
||||||
|
GlideSpeed = config.Bind(section, $"{form} Glide Speed", glide,
|
||||||
|
OrderedDesc($"{form} speed while gliding with no key held, in m/s.", new AcceptableValueRange<float>(0f, 30f), order--)),
|
||||||
|
BoostSpeed = config.Bind(section, $"{form} Boost Speed", boost,
|
||||||
|
OrderedDesc($"{form} speed while holding W, in m/s. Costs the flight stamina below.", new AcceptableValueRange<float>(0f, 50f), order--)),
|
||||||
|
SprintSpeed = config.Bind(section, $"{form} Sprint Speed", sprint,
|
||||||
|
OrderedDesc($"{form} speed while holding W and Shift, in m/s. Costs the sprint stamina on top.", new AcceptableValueRange<float>(0f, 60f), order--)),
|
||||||
|
ReverseSpeed = config.Bind(section, $"{form} Reverse Speed", reverse,
|
||||||
|
OrderedDesc($"{form} speed while holding S, in m/s. Costs the flight stamina.", new AcceptableValueRange<float>(0f, 30f), order--)),
|
||||||
|
LiftoffSpeed = config.Bind(section, $"{form} Liftoff Speed", liftoff,
|
||||||
|
OrderedDesc($"{form} climb speed out of water, in m/s. Always free, so a form that touches the sea can still leave it.", new AcceptableValueRange<float>(0f, 30f), order--)),
|
||||||
|
HoverSeconds = config.Bind(section, $"{form} Hover Seconds", hover,
|
||||||
|
OrderedDesc($"How long the {form} holds its height after the last powered beat before it starts to sink.", new AcceptableValueRange<float>(0f, 30f), order--)),
|
||||||
|
PoweredStaminaPerSecond = config.Bind(section, $"{form} Flight Stamina Per Second", powered,
|
||||||
|
OrderedDesc($"Stamina per second while the {form} holds W or S. Out of stamina, it can only glide. 0 makes flight free.", new AcceptableValueRange<float>(0f, 60f), order--)),
|
||||||
|
SprintStaminaPerSecond = config.Bind(section, $"{form} Sprint Stamina Per Second", sprintCost,
|
||||||
|
OrderedDesc($"Extra stamina per second while the {form} sprints, on top of the flight cost.", new AcceptableValueRange<float>(0f, 60f), order--)),
|
||||||
|
Encumbered = config.Bind(section, $"{form} While Encumbered", encumbered,
|
||||||
|
OrderedDesc($"Allowed: the {form} flies while you carry too much, at the extra stamina cost below. Blocked: it cannot take off while you are encumbered, and one that becomes encumbered in the air can only glide down. It still walks.", null, order--)),
|
||||||
|
EncumberedExtraCost = config.Bind(section, $"{form} Encumbered Extra Stamina Cost", extraCost,
|
||||||
|
OrderedDesc($"With 'Allowed' above: how much more the {form}'s flight and sprint cost while encumbered. 0.25 = 25% more.", new AcceptableValueRange<float>(0f, 1f), order--)),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
private static FormTiming BindTiming(ConfigFile config, string section, string form, ref int order)
|
||||||
|
{
|
||||||
|
return new FormTiming
|
||||||
|
{
|
||||||
|
MaxDuration = config.Bind(section, $"{form} Max Duration", -1f,
|
||||||
|
OrderedDesc($"Seconds the {form} form lasts before you turn back on your own. -1 follows the boss tiers (see the Compendium), 0 means no limit.", new AcceptableValueRange<float>(-1f, 3600f), order--)),
|
||||||
|
DurationPerState = config.Bind(section, $"{form} Duration Per State", 0f,
|
||||||
|
OrderedDesc($"Seconds added to the {form}'s max duration per progression state. Only counts when Max Duration is above 0.", new AcceptableValueRange<float>(0f, 600f), order--)),
|
||||||
|
Cooldown = config.Bind(section, $"{form} Cooldown", -1f,
|
||||||
|
OrderedDesc($"Seconds after leaving the {form} form before you can take it again. -1 follows the boss tiers, 0 means none.", new AcceptableValueRange<float>(-1f, 3600f), order--)),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
private static ConfigDescription OrderedDesc(string description, AcceptableValueBase range, int order)
|
||||||
|
{
|
||||||
|
return new ConfigDescription(description, range, new ConfigurationManagerAttributes { Order = order });
|
||||||
}
|
}
|
||||||
|
|
||||||
private static ConfigDescription KeyDesc(string description, int order)
|
private static ConfigDescription KeyDesc(string description, int order)
|
||||||
|
|
|
||||||
|
|
@ -316,221 +316,7 @@ namespace RacesOfValheim
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// DrakeFormBehavior flips the player into Character's native flying-creature movement
|
// Directed flight (the controls) lives in DirectedFlight.cs, shared with the Aswid's bat.
|
||||||
// (m_flying = true) instead of the old debug-fly noclip, which lets us feed it a full 3D
|
|
||||||
// move direction. Character.UpdateFlying normally reads whatever m_moveDir the vanilla input
|
|
||||||
// pipeline last wrote (ground-plane WASD relative to camera yaw only); this patch overwrites
|
|
||||||
// it every frame with the camera's actual look direction (pitch included) so the player always
|
|
||||||
// glides toward wherever the mouse is aiming, with W powering forward, Shift spending stamina
|
|
||||||
// for a burst of speed, and S beating backwards away from whatever you are looking at.
|
|
||||||
[HarmonyPatch(typeof(Character), "UpdateFlying")]
|
|
||||||
public static class SkadiDirectedFlightPatch
|
|
||||||
{
|
|
||||||
// Read from SkadiConfig (BepInEx Config) rather than fixed constants, so flight can be
|
|
||||||
// retuned from Configuration Manager - see CONFIGURATION-MANAGER-HOWTO.md.
|
|
||||||
private static float TURN_SPEED => SkadiConfig.FlightTurnSpeed.Value;
|
|
||||||
private static float GLIDE_SPEED => SkadiConfig.FlightGlideSpeed.Value;
|
|
||||||
private static float BOOST_SPEED => SkadiConfig.FlightBoostSpeed.Value;
|
|
||||||
private static float SPRINT_SPEED => SkadiConfig.FlightSprintSpeed.Value;
|
|
||||||
private static float REVERSE_SPEED => SkadiConfig.FlightReverseSpeed.Value;
|
|
||||||
// Climbing out of water is deliberately slower than a powered climb in open air - the
|
|
||||||
// wings are dragging themselves free, not racing.
|
|
||||||
private static float LIFTOFF_SPEED => SkadiConfig.FlightLiftoffSpeed.Value;
|
|
||||||
private static float HOVER_SECONDS => SkadiConfig.FlightHoverSeconds.Value;
|
|
||||||
// Per second, drained only while the sprint is actually being granted.
|
|
||||||
private static float SPRINT_STAMINA_PER_SECOND => SkadiConfig.FlightSprintStaminaPerSecond.Value;
|
|
||||||
// Tangent of the unpowered descent angle: 0.4 sinks at roughly 22 degrees below level.
|
|
||||||
private const float DESCENT_SLOPE = 0.4f;
|
|
||||||
// How much of the aim heading survives the climb out of water. Mostly up, with enough
|
|
||||||
// forward in it that the player still chooses which shore they surface towards.
|
|
||||||
private const float LIFTOFF_HEADING_BLEND = 0.35f;
|
|
||||||
// How far the left stick has to be pushed before it counts as W or S.
|
|
||||||
private const float StickThreshold = 0.5f;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// True while the local player is beating backwards this frame. Read by
|
|
||||||
/// SkadiReverseFacingPatch, which keeps the body pointed at the camera while it happens.
|
|
||||||
/// </summary>
|
|
||||||
public static bool Reversing { get; private set; }
|
|
||||||
|
|
||||||
// The September 2026 hotfix dropped the bool parameter from ZInput.GetJoyLeftStickY.
|
|
||||||
// A direct call binds to whichever signature we compiled against and throws
|
|
||||||
// MissingMethodException on the other, so resolve it at runtime and accept either.
|
|
||||||
private static readonly MethodInfo JoyLeftStickYMethod =
|
|
||||||
AccessTools.Method(typeof(ZInput), "GetJoyLeftStickY", new System.Type[0]) ??
|
|
||||||
AccessTools.Method(typeof(ZInput), "GetJoyLeftStickY", new[] { typeof(bool) });
|
|
||||||
|
|
||||||
private static float JoyLeftStickY()
|
|
||||||
{
|
|
||||||
if (JoyLeftStickYMethod == null) return 0f;
|
|
||||||
return (float)JoyLeftStickYMethod.Invoke(null, JoyLeftStickYArgs);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Old signature: pass smooth = true, which was its default.
|
|
||||||
private static readonly object[] JoyLeftStickYArgs =
|
|
||||||
JoyLeftStickYMethod != null && JoyLeftStickYMethod.GetParameters().Length == 1 ? new object[] { true } : null;
|
|
||||||
|
|
||||||
public static void Prefix(Character __instance, float dt)
|
|
||||||
{
|
|
||||||
if (__instance != Player.m_localPlayer) return;
|
|
||||||
|
|
||||||
DrakeFormBehavior form = DrakeFormBehavior.Active;
|
|
||||||
if (form == null || !form.IsFlying)
|
|
||||||
{
|
|
||||||
Reversing = false;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var traverse = Traverse.Create(__instance);
|
|
||||||
Vector3 lookDir = Player.m_localPlayer.GetLookDir();
|
|
||||||
bool input = RaceInput.Allowed;
|
|
||||||
// The pad's half of W/S: the left stick, read with vanilla's own sign -
|
|
||||||
// PlayerController.FixedUpdate takes forward as the NEGATED GetJoyLeftStickY.
|
|
||||||
// Flight only knows powered forward, reverse or neither, so the stick is a
|
|
||||||
// threshold, not a throttle. Steering stays on the camera, i.e. the right stick.
|
|
||||||
float stick = -JoyLeftStickY();
|
|
||||||
bool forward = input && (Input.GetKey(KeyCode.W) || stick > StickThreshold);
|
|
||||||
// Forward wins a W+S mash rather than the two cancelling into a dead hover.
|
|
||||||
bool backward = input && !forward && (Input.GetKey(KeyCode.S) || stick < -StickThreshold);
|
|
||||||
// Sprint on a pad is vanilla's run button, wherever the chosen layout puts it.
|
|
||||||
bool sprintKey = input && (Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift) ||
|
|
||||||
ZInput.GetButton("JoyRun"));
|
|
||||||
bool onGround = __instance.IsOnGround();
|
|
||||||
// IsSwimming is the exact test UpdateMotion uses to hand the frame to UpdateSwimming
|
|
||||||
// instead of UpdateFlying, so it is also the one condition SkadiWaterFlightPatch has
|
|
||||||
// to take back. Its half-second tail past leaving the water is welcome here - it
|
|
||||||
// keeps the climb going just long enough to clear the surface properly.
|
|
||||||
bool inWater = __instance.IsSwimming();
|
|
||||||
|
|
||||||
Reversing = backward;
|
|
||||||
|
|
||||||
// m_run only picks between the two fly speeds. Every mode now has its own speed, so
|
|
||||||
// leave it off and drive all of them through m_flySlowSpeed.
|
|
||||||
traverse.Field("m_run").SetValue(false);
|
|
||||||
|
|
||||||
// UpdateFlying rotates the body toward m_moveDir on its own, but at m_flyTurnSpeed,
|
|
||||||
// which sits at Character's 12 deg/s default because the Player prefab was never set
|
|
||||||
// up as a flying creature - a 90 degree turn would take over seven seconds, so the
|
|
||||||
// model reads as not turning at all. Give it a speed that suits a flying mount.
|
|
||||||
traverse.Field("m_flyTurnSpeed").SetValue(TURN_SPEED);
|
|
||||||
|
|
||||||
// Powered flight, ground contact and clawing out of water all refresh the hover
|
|
||||||
// window, so none of them can be followed by an immediate sink.
|
|
||||||
if (forward || backward || onGround || inWater) form.LastPoweredTime = Time.time;
|
|
||||||
|
|
||||||
Vector3 moveDir = lookDir;
|
|
||||||
float speed;
|
|
||||||
|
|
||||||
if (inWater)
|
|
||||||
{
|
|
||||||
// Wet wings still beat. Water used to be a trap: UpdateMotion hands a swimming
|
|
||||||
// character to UpdateSwimming before it ever looks at m_flying, so a dragon that
|
|
||||||
// touched the sea was stuck paddling with the flight controls doing nothing.
|
|
||||||
// SkadiWaterFlightPatch gives the frame back to flight, and this branch spends it
|
|
||||||
// climbing regardless of where the camera points, so the surface is always
|
|
||||||
// something you break out of rather than something you sit in.
|
|
||||||
moveDir = (Vector3.up + FlatHeading(__instance, lookDir) * LIFTOFF_HEADING_BLEND).normalized;
|
|
||||||
speed = LIFTOFF_SPEED;
|
|
||||||
}
|
|
||||||
else if (backward)
|
|
||||||
{
|
|
||||||
// Straight reverse thrust along the aim, pitch included: look down and beat back
|
|
||||||
// and you rise away from what you are looking at, which is the whole point of
|
|
||||||
// having a reverse - you can retreat without taking your eyes (or your breath
|
|
||||||
// attack, which fires along the same vector) off the target.
|
|
||||||
moveDir = -lookDir;
|
|
||||||
speed = REVERSE_SPEED;
|
|
||||||
}
|
|
||||||
else if (forward)
|
|
||||||
{
|
|
||||||
speed = BOOST_SPEED;
|
|
||||||
// The sprint is the only part of flight that costs anything. Base flight stays
|
|
||||||
// free on purpose - the drake arrives at the Elder, long before the player has
|
|
||||||
// the stamina pool to pay for simply staying airborne.
|
|
||||||
if (sprintKey && TrySpendSprintStamina(dt)) speed = SPRINT_SPEED;
|
|
||||||
}
|
|
||||||
else if (onGround || Time.time - form.LastPoweredTime < HOVER_SECONDS)
|
|
||||||
{
|
|
||||||
// Holding station: on the ground this keeps a touchdown from sliding the player
|
|
||||||
// forward forever, and in the air it gives the beats of level flight before the
|
|
||||||
// form starts to sink. m_moveDir stays full length so the body still turns to
|
|
||||||
// face the camera, and zeroing the speed (rather than the rigidbody velocity)
|
|
||||||
// avoids fighting the AddForce UpdateFlying queues, which caused visible jitter.
|
|
||||||
speed = 0f;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// Unpowered flight is a glide, not a hover with a joystick: drift along the
|
|
||||||
// heading the camera faces while losing height, so aiming at the sky without
|
|
||||||
// holding W no longer climbs.
|
|
||||||
moveDir = (FlatHeading(__instance, lookDir) + Vector3.down * DESCENT_SLOPE).normalized;
|
|
||||||
speed = GLIDE_SPEED;
|
|
||||||
}
|
|
||||||
|
|
||||||
traverse.Field("m_moveDir").SetValue(moveDir);
|
|
||||||
traverse.Field("m_flySlowSpeed").SetValue(speed);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>Aim flattened onto the ground plane, falling back to the body's own facing
|
|
||||||
/// when the player is looking straight up or down.</summary>
|
|
||||||
private static Vector3 FlatHeading(Character character, Vector3 lookDir)
|
|
||||||
{
|
|
||||||
Vector3 heading = new Vector3(lookDir.x, 0f, lookDir.z);
|
|
||||||
if (heading.sqrMagnitude < 0.0001f)
|
|
||||||
{
|
|
||||||
heading = character.transform.forward;
|
|
||||||
heading.y = 0f;
|
|
||||||
}
|
|
||||||
return heading.normalized;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Charges this frame of sprint. Returns false when the player cannot pay, which drops
|
|
||||||
/// them back to the free boost speed rather than out of the sky.
|
|
||||||
/// </summary>
|
|
||||||
private static bool TrySpendSprintStamina(float dt)
|
|
||||||
{
|
|
||||||
Player player = Player.m_localPlayer;
|
|
||||||
if (player == null) return false;
|
|
||||||
|
|
||||||
float cost = SPRINT_STAMINA_PER_SECOND * dt;
|
|
||||||
if (!player.HaveStamina(cost)) return false;
|
|
||||||
|
|
||||||
player.UseStamina(cost);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Character.UpdateMotion asks IsSwimming before it asks m_flying, so a flying dragon that
|
|
||||||
/// touched water was handed to UpdateSwimming every frame: the flight patch above never ran,
|
|
||||||
/// the form paddled on the surface, and there was no way back into the air short of finding
|
|
||||||
/// land. (The Aswid's bat escapes this because debug-fly is checked at the very top of
|
|
||||||
/// UpdateMotion, before water is considered at all - which is exactly why it can take off
|
|
||||||
/// from the sea.) Hand those frames back to UpdateFlying, which is the only motion path the
|
|
||||||
/// two methods contend over: nothing else calls either of them, and everything that merely
|
|
||||||
/// asks IsSwimming - the Wet status, the animator, stamina - is left alone.
|
|
||||||
/// </summary>
|
|
||||||
[HarmonyPatch(typeof(Character), "UpdateSwimming")]
|
|
||||||
public static class SkadiWaterFlightPatch
|
|
||||||
{
|
|
||||||
private static readonly MethodInfo UpdateFlyingMethod = AccessTools.Method(typeof(Character), "UpdateFlying");
|
|
||||||
|
|
||||||
public static bool Prefix(Character __instance, float dt)
|
|
||||||
{
|
|
||||||
if (__instance != Player.m_localPlayer) return true;
|
|
||||||
|
|
||||||
DrakeFormBehavior form = DrakeFormBehavior.Active;
|
|
||||||
if (form == null || !form.IsFlying) return true;
|
|
||||||
|
|
||||||
// Fail open: if a game update ever renames the method, swim normally rather than
|
|
||||||
// freezing the player in place with no motion update at all.
|
|
||||||
if (UpdateFlyingMethod == null) return true;
|
|
||||||
|
|
||||||
UpdateFlyingMethod.Invoke(__instance, new object[] { dt });
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// UpdateFlying turns the body to face m_moveDir, which is right for every direction of
|
/// UpdateFlying turns the body to face m_moveDir, which is right for every direction of
|
||||||
|
|
@ -559,10 +345,8 @@ namespace RacesOfValheim
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!SkadiDirectedFlightPatch.Reversing) return true;
|
if (!DirectedFlightPatch.Reversing) return true;
|
||||||
|
if (DirectedFlight.Flying == null) return true;
|
||||||
DrakeFormBehavior form = DrakeFormBehavior.Active;
|
|
||||||
if (form == null || !form.IsFlying) return true;
|
|
||||||
|
|
||||||
__result = true;
|
__result = true;
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -624,7 +408,11 @@ namespace RacesOfValheim
|
||||||
public static bool Prefix(Humanoid __instance)
|
public static bool Prefix(Humanoid __instance)
|
||||||
{
|
{
|
||||||
if (__instance != Player.m_localPlayer) return true;
|
if (__instance != Player.m_localPlayer) return true;
|
||||||
return __instance.GetComponentInChildren<DrakeFormBehavior>() == null;
|
if (__instance.GetComponentInChildren<DrakeFormBehavior>() == null) return true;
|
||||||
|
|
||||||
|
// The dragon's own clip calling its blow: the hit cue for the form's melee.
|
||||||
|
DrakeFormBehavior.NotifyAttackTrigger();
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -85,7 +85,9 @@ namespace RacesOfValheim
|
||||||
rules.Form = FormType.Drake;
|
rules.Form = FormType.Drake;
|
||||||
rules.CanAttackInForm = false;
|
rules.CanAttackInForm = false;
|
||||||
}
|
}
|
||||||
return rules.Form != FormType.None ? rules : null;
|
if (rules.Form == FormType.None) return null;
|
||||||
|
ApplyTiming(rules, SkadiConfig.DrakeTiming, state);
|
||||||
|
return rules;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static FormRules GetHKeyRules(int state)
|
public static FormRules GetHKeyRules(int state)
|
||||||
|
|
@ -112,7 +114,9 @@ namespace RacesOfValheim
|
||||||
rules.CooldownMinutes = 10f;
|
rules.CooldownMinutes = 10f;
|
||||||
rules.CanAttackInForm = true;
|
rules.CanAttackInForm = true;
|
||||||
}
|
}
|
||||||
return rules.Form != FormType.None ? rules : null;
|
if (rules.Form == FormType.None) return null;
|
||||||
|
ApplyTiming(rules, SkadiConfig.ModerTiming, state);
|
||||||
|
return rules;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static FormRules GetJKeyRules(int state)
|
public static FormRules GetJKeyRules(int state)
|
||||||
|
|
@ -125,7 +129,27 @@ namespace RacesOfValheim
|
||||||
rules.CooldownMinutes = 0f;
|
rules.CooldownMinutes = 0f;
|
||||||
rules.CanAttackInForm = true;
|
rules.CanAttackInForm = true;
|
||||||
}
|
}
|
||||||
return rules.Form != FormType.None ? rules : null;
|
if (rules.Form == FormType.None) return null;
|
||||||
|
ApplyTiming(rules, SkadiConfig.FaderTiming, state);
|
||||||
|
return rules;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The config's timing on top of the tier table above: -1 leaves the table's value, 0 or
|
||||||
|
/// more replaces it. Per-state seconds only stretch a limit that exists, as on the bat.
|
||||||
|
/// </summary>
|
||||||
|
private static void ApplyTiming(FormRules rules, SkadiConfig.FormTiming timing, int state)
|
||||||
|
{
|
||||||
|
if (timing == null) return;
|
||||||
|
|
||||||
|
float max = timing.MaxDuration.Value;
|
||||||
|
if (max >= 0f)
|
||||||
|
rules.DurationMinutes = max > 0f ? (max + timing.DurationPerState.Value * state) / 60f : 0f;
|
||||||
|
else if (rules.DurationMinutes > 0f)
|
||||||
|
rules.DurationMinutes += timing.DurationPerState.Value * state / 60f;
|
||||||
|
|
||||||
|
float cooldown = timing.Cooldown.Value;
|
||||||
|
if (cooldown >= 0f) rules.CooldownMinutes = cooldown / 60f;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -79,11 +79,11 @@ namespace RacesOfValheim
|
||||||
// drake one used for the passive blessing.
|
// drake one used for the passive blessing.
|
||||||
Sprite dragonIcon = GetItemIcon("TrophyDragonQueen") ?? GetItemIcon("TrophyHatchling");
|
Sprite dragonIcon = GetItemIcon("TrophyDragonQueen") ?? GetItemIcon("TrophyHatchling");
|
||||||
|
|
||||||
skadiCdSE = ScriptableObject.CreateInstance<SE_FormCooldown>();
|
// One cooldown per form, so a Drake cooldown set in the config never holds the Moder
|
||||||
skadiCdSE.name = "SE_SkadiCooldown";
|
// back, nor the other way round. The Moder keeps the original name.
|
||||||
skadiCdSE.m_name = "$rov_se_skadi_formcd_name";
|
skadiCdSE = RegisterFormCooldown(SkadiProgression.FormType.Moder, "$rov_se_skadi_formcd_name", dragonIcon);
|
||||||
skadiCdSE.m_icon = dragonIcon;
|
RegisterFormCooldown(SkadiProgression.FormType.Drake, "$rov_se_skadi_drakecd_name", GetItemIcon("TrophyHatchling") ?? dragonIcon);
|
||||||
ItemManager.Instance.AddStatusEffect(new CustomStatusEffect(skadiCdSE, fixReference: false));
|
RegisterFormCooldown(SkadiProgression.FormType.SkeletonDragon, "$rov_se_skadi_fadercd_name", GetItemIcon("TrophyFader") ?? dragonIcon);
|
||||||
|
|
||||||
skadiFormSE = ScriptableObject.CreateInstance<SE_SkadiForm>();
|
skadiFormSE = ScriptableObject.CreateInstance<SE_SkadiForm>();
|
||||||
skadiFormSE.name = "SE_SkadiForm";
|
skadiFormSE.name = "SE_SkadiForm";
|
||||||
|
|
@ -124,6 +124,26 @@ namespace RacesOfValheim
|
||||||
if (se != null) se.m_ttl = seconds;
|
if (se != null) se.m_ttl = seconds;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static SE_FormCooldown RegisterFormCooldown(SkadiProgression.FormType form, string displayName, Sprite icon)
|
||||||
|
{
|
||||||
|
SE_FormCooldown cd = ScriptableObject.CreateInstance<SE_FormCooldown>();
|
||||||
|
cd.name = CooldownSEName(form);
|
||||||
|
cd.m_name = displayName;
|
||||||
|
cd.m_icon = icon;
|
||||||
|
ItemManager.Instance.AddStatusEffect(new CustomStatusEffect(cd, fixReference: false));
|
||||||
|
return cd;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static string CooldownSEName(SkadiProgression.FormType form)
|
||||||
|
{
|
||||||
|
switch (form)
|
||||||
|
{
|
||||||
|
case SkadiProgression.FormType.Drake: return "SE_SkadiCooldown_Drake";
|
||||||
|
case SkadiProgression.FormType.SkeletonDragon: return "SE_SkadiCooldown_Fader";
|
||||||
|
default: return "SE_SkadiCooldown";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static Sprite GetItemIcon(string prefabName)
|
private static Sprite GetItemIcon(string prefabName)
|
||||||
{
|
{
|
||||||
GameObject trophy = PrefabManager.Cache.GetPrefab<ItemDrop>(prefabName)?.gameObject;
|
GameObject trophy = PrefabManager.Cache.GetPrefab<ItemDrop>(prefabName)?.gameObject;
|
||||||
|
|
@ -465,13 +485,7 @@ namespace RacesOfValheim
|
||||||
/// mode and with nothing in either hand. Shared with SkadiAttackPatch, which swallows the
|
/// mode and with nothing in either hand. Shared with SkadiAttackPatch, which swallows the
|
||||||
/// unarmed kick under exactly the same condition.
|
/// unarmed kick under exactly the same condition.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static bool PadCastsColdSpell(Player player)
|
public static bool PadCastsColdSpell(Player player) => RaceInput.EmptyHanded(player);
|
||||||
{
|
|
||||||
if (player == null || player.InPlaceMode()) return false;
|
|
||||||
var hands = HarmonyLib.Traverse.Create(player);
|
|
||||||
return hands.Field<ItemDrop.ItemData>("m_rightItem").Value == null &&
|
|
||||||
hands.Field<ItemDrop.ItemData>("m_leftItem").Value == null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private IEnumerator ColdSpellKickCoroutine(SkadiProgression.FormRules rules)
|
private IEnumerator ColdSpellKickCoroutine(SkadiProgression.FormRules rules)
|
||||||
{
|
{
|
||||||
|
|
@ -693,7 +707,7 @@ namespace RacesOfValheim
|
||||||
|
|
||||||
if (rules.CooldownMinutes > 0)
|
if (rules.CooldownMinutes > 0)
|
||||||
{
|
{
|
||||||
var cdSE = Player.m_localPlayer.GetSEMan().GetStatusEffect("SE_SkadiCooldown".GetStableHashCode());
|
var cdSE = Player.m_localPlayer.GetSEMan().GetStatusEffect(CooldownSEName(rules.Form).GetStableHashCode());
|
||||||
if (cdSE != null)
|
if (cdSE != null)
|
||||||
{
|
{
|
||||||
float m_time = HarmonyLib.Traverse.Create(cdSE).Field<float>("m_time").Value;
|
float m_time = HarmonyLib.Traverse.Create(cdSE).Field<float>("m_time").Value;
|
||||||
|
|
@ -989,8 +1003,9 @@ namespace RacesOfValheim
|
||||||
|
|
||||||
if (activeRules != null && activeRules.CooldownMinutes > 0)
|
if (activeRules != null && activeRules.CooldownMinutes > 0)
|
||||||
{
|
{
|
||||||
Player.m_localPlayer.GetSEMan().AddStatusEffect("SE_SkadiCooldown".GetStableHashCode(), true);
|
int cdHash = CooldownSEName(activeRules.Form).GetStableHashCode();
|
||||||
var cdSE = Player.m_localPlayer.GetSEMan().GetStatusEffect("SE_SkadiCooldown".GetStableHashCode());
|
Player.m_localPlayer.GetSEMan().AddStatusEffect(cdHash, true);
|
||||||
|
var cdSE = Player.m_localPlayer.GetSEMan().GetStatusEffect(cdHash);
|
||||||
if (cdSE != null) cdSE.m_ttl = activeRules.CooldownMinutes * 60f;
|
if (cdSE != null) cdSE.m_ttl = activeRules.CooldownMinutes * 60f;
|
||||||
}
|
}
|
||||||
activeRules = null;
|
activeRules = null;
|
||||||
|
|
|
||||||
|
|
@ -47,6 +47,11 @@ namespace RacesOfValheim
|
||||||
public static ConfigEntry<bool> HeadFireVFXEnabled;
|
public static ConfigEntry<bool> HeadFireVFXEnabled;
|
||||||
public static ConfigEntry<bool> BodyModelEnabled;
|
public static ConfigEntry<bool> BodyModelEnabled;
|
||||||
public static ConfigEntry<bool> RaiseDeadIcon;
|
public static ConfigEntry<bool> RaiseDeadIcon;
|
||||||
|
public static ConfigEntry<bool> ShowHelmet;
|
||||||
|
|
||||||
|
// ─── Mortal Habits (per player) ────────────────────────────────────────
|
||||||
|
public static ConfigEntry<bool> EatsMortalFood;
|
||||||
|
public static ConfigEntry<bool> FeelsFatigue;
|
||||||
|
|
||||||
public static void Bind(ConfigFile config)
|
public static void Bind(ConfigFile config)
|
||||||
{
|
{
|
||||||
|
|
@ -86,6 +91,17 @@ namespace RacesOfValheim
|
||||||
new ConfigDescription("Whether Skeleton players wear the skeleton body. Turn it off if you use a player model mod (EnhancedValheimVRM and the like): Skeletons then keep the vanilla viking body, so the replacement model shows without bones clipping through it. Abilities are unchanged. Client-side, like the option above: it applies to every Skeleton you see, yourself included, and changes nothing for other players."));
|
new ConfigDescription("Whether Skeleton players wear the skeleton body. Turn it off if you use a player model mod (EnhancedValheimVRM and the like): Skeletons then keep the vanilla viking body, so the replacement model shows without bones clipping through it. Abilities are unchanged. Client-side, like the option above: it applies to every Skeleton you see, yourself included, and changes nothing for other players."));
|
||||||
RaiseDeadIcon = config.Bind(visuals, "Raise the Dead Icon", true,
|
RaiseDeadIcon = config.Bind(visuals, "Raise the Dead Icon", true,
|
||||||
new ConfigDescription("Shows the Raise the Dead status icon while your Summon on Kill is on."));
|
new ConfigDescription("Shows the Raise the Dead status icon while your Summon on Kill is on."));
|
||||||
|
ShowHelmet = config.Bind(visuals, "Show Helmet", false,
|
||||||
|
new ConfigDescription("Off: your helmet stays hidden over the skull. On: the helmet you wear shows. Helmets and hoods are moved and enlarged to fit the skull. Your own choice: other players see you the way you picked. A viking body (Body Model Enabled off) always shows its helmet."));
|
||||||
|
|
||||||
|
// For groups who want the Skeleton but miss Valheim's food or stamina. Both only take
|
||||||
|
// away an advantage (permanent best-tier food, infinite stamina), so each player picks
|
||||||
|
// for themselves and the server does not sync them.
|
||||||
|
const string habits = "Skeleton - Mortal Habits";
|
||||||
|
EatsMortalFood = config.Bind(habits, "Eats Mortal Food", false,
|
||||||
|
new ConfigDescription("Off: you never eat, and your Maximum Health comes from your standing (the bosses you have defeated). On: you eat like the living, your health and stamina come from your meals, and the standing's health bonus is gone. Your other Skeleton powers stay. Your own choice, not synced by the server."));
|
||||||
|
FeelsFatigue = config.Bind(habits, "Feels Fatigue", false,
|
||||||
|
new ConfigDescription("Off: you have no stamina and never tire. On: you spend stamina like the living. Without Eats Mortal Food your stamina grows with your standing, from the same meals your health is measured by. Your own choice, not synced by the server."));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -44,16 +44,26 @@ namespace RacesOfValheim
|
||||||
/// GetTotalFoodValue has exactly one caller, Player.UpdateFood, which passes the result
|
/// GetTotalFoodValue has exactly one caller, Player.UpdateFood, which passes the result
|
||||||
/// straight to SetMaxHealth - so this is the single point where the number is decided, and
|
/// straight to SetMaxHealth - so this is the single point where the number is decided, and
|
||||||
/// it now comes from the progression table rather than from three scaled sausages.
|
/// it now comes from the progression table rather than from three scaled sausages.
|
||||||
|
///
|
||||||
|
/// A Skeleton with "Eats Mortal Food" is left to vanilla: its real meals decide both
|
||||||
|
/// numbers, and the tier's health, which stands in for those meals, does not stack on top.
|
||||||
|
/// One with "Feels Fatigue" who does not eat gets the stand-in meals' stamina, which the
|
||||||
|
/// fake foods themselves never deliver.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[HarmonyPatch(typeof(Player), "GetTotalFoodValue")]
|
[HarmonyPatch(typeof(Player), "GetTotalFoodValue")]
|
||||||
public static class Player_GetTotalFoodValue_SkeletonHealth_Patch
|
public static class Player_GetTotalFoodValue_SkeletonHealth_Patch
|
||||||
{
|
{
|
||||||
public static void Postfix(Player __instance, ref float hp)
|
public static void Postfix(Player __instance, ref float hp, ref float stamina)
|
||||||
{
|
{
|
||||||
if (__instance != Player.m_localPlayer || !SkeletonRace.IsSkeleton()) return;
|
if (__instance != Player.m_localPlayer || !SkeletonRace.IsSkeleton()) return;
|
||||||
|
if (SkeletonConfig.EatsMortalFood.Value) return;
|
||||||
|
|
||||||
int state = BossProgressionManager.GetCurrentProgressionState();
|
int state = BossProgressionManager.GetCurrentProgressionState();
|
||||||
hp = __instance.m_baseHP + SkeletonProgression.GetMaxHealthBonus(state);
|
hp = __instance.m_baseHP + SkeletonProgression.GetMaxHealthBonus(state);
|
||||||
|
if (SkeletonConfig.FeelsFatigue.Value)
|
||||||
|
{
|
||||||
|
stamina = __instance.m_baseStamina + SkeletonRace.GetStandInStamina(state);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -62,7 +72,8 @@ namespace RacesOfValheim
|
||||||
{
|
{
|
||||||
public static bool Prefix(Player __instance)
|
public static bool Prefix(Player __instance)
|
||||||
{
|
{
|
||||||
if ((SkeletonRace.IsSkeleton() || AswidRace.IsAswid() || DraughRace.IsDraugh()) && __instance == Player.m_localPlayer)
|
// The Aswid used to be on this list. It spends stamina now, see Aswid_UseStamina_Patch.
|
||||||
|
if (((SkeletonRace.IsSkeleton() && !SkeletonConfig.FeelsFatigue.Value) || DraughRace.IsDraugh()) && __instance == Player.m_localPlayer)
|
||||||
{
|
{
|
||||||
// Infinite stamina: skip the original UseStamina method
|
// Infinite stamina: skip the original UseStamina method
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -78,7 +89,7 @@ namespace RacesOfValheim
|
||||||
{
|
{
|
||||||
if (__instance == Player.m_localPlayer)
|
if (__instance == Player.m_localPlayer)
|
||||||
{
|
{
|
||||||
if (SkeletonRace.IsSkeleton() && item.m_shared.m_itemType == ItemDrop.ItemData.ItemType.Consumable && (item.m_shared.m_food > 0 || item.m_shared.m_foodStamina > 0 || item.m_shared.m_foodEitr > 0))
|
if (SkeletonRace.IsSkeleton() && !SkeletonConfig.EatsMortalFood.Value && item.m_shared.m_itemType == ItemDrop.ItemData.ItemType.Consumable && (item.m_shared.m_food > 0 || item.m_shared.m_foodStamina > 0 || item.m_shared.m_foodEitr > 0))
|
||||||
{
|
{
|
||||||
__instance.Message(MessageHud.MessageType.Center, ModText.Get("rov_msg_skeleton_skeletons_do_not_need_eat"));
|
__instance.Message(MessageHud.MessageType.Center, ModText.Get("rov_msg_skeleton_skeletons_do_not_need_eat"));
|
||||||
__result = false;
|
__result = false;
|
||||||
|
|
@ -193,7 +204,7 @@ namespace RacesOfValheim
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (player == Player.m_localPlayer && SkeletonRace.IsSkeleton())
|
if (player == Player.m_localPlayer && SkeletonRace.IsSkeleton() && !SkeletonConfig.EatsMortalFood.Value)
|
||||||
{
|
{
|
||||||
if (__instance.m_foodBarRoot != null && __instance.m_foodBarRoot.gameObject.activeSelf)
|
if (__instance.m_foodBarRoot != null && __instance.m_foodBarRoot.gameObject.activeSelf)
|
||||||
{
|
{
|
||||||
|
|
@ -232,7 +243,7 @@ namespace RacesOfValheim
|
||||||
}
|
}
|
||||||
catch (System.Exception e)
|
catch (System.Exception e)
|
||||||
{
|
{
|
||||||
if (player == Player.m_localPlayer && SkeletonRace.IsSkeleton()) return false;
|
if (player == Player.m_localPlayer && SkeletonRace.IsSkeleton() && !SkeletonConfig.EatsMortalFood.Value) return false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -350,7 +361,7 @@ namespace RacesOfValheim
|
||||||
|
|
||||||
HideItemInstances(__instance, "m_hairItemInstance");
|
HideItemInstances(__instance, "m_hairItemInstance");
|
||||||
HideItemInstances(__instance, "m_beardItemInstance");
|
HideItemInstances(__instance, "m_beardItemInstance");
|
||||||
SetHelmetVisible(__instance, false);
|
SkeletonVisuals.FitHelmet(p, __instance, SkeletonVisuals.ShowsHelmet(p));
|
||||||
|
|
||||||
// Poses the mandible, once per frame, after the animation. Attached from
|
// Poses the mandible, once per frame, after the animation. Attached from
|
||||||
// here rather than from SkeletonRace because this postfix is the one path
|
// here rather than from SkeletonRace because this postfix is the one path
|
||||||
|
|
@ -395,7 +406,7 @@ namespace RacesOfValheim
|
||||||
|
|
||||||
ShowItemInstances(__instance, "m_hairItemInstance");
|
ShowItemInstances(__instance, "m_hairItemInstance");
|
||||||
ShowItemInstances(__instance, "m_beardItemInstance");
|
ShowItemInstances(__instance, "m_beardItemInstance");
|
||||||
SetHelmetVisible(__instance, true);
|
SkeletonVisuals.UnfitHelmet(__instance);
|
||||||
|
|
||||||
// Parented to rig bones, not to the body container that was just switched
|
// Parented to rig bones, not to the body container that was just switched
|
||||||
// off above - so without this a human keeps the skeleton's lit sockets.
|
// off above - so without this a human keeps the skeleton's lit sockets.
|
||||||
|
|
@ -404,26 +415,6 @@ namespace RacesOfValheim
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// A helmet on a skull looks like a helmet floating in a skull, so the race hides it.
|
|
||||||
///
|
|
||||||
/// SkeletonRace does this every frame in a world, but it only ever runs for the local
|
|
||||||
/// player - which is why the helmet came back on the main-menu preview once the body
|
|
||||||
/// swap started working there. Doing it here covers the menu, remote players and the
|
|
||||||
/// first frame after a race change, all of which reach this postfix and none of which
|
|
||||||
/// reach SkeletonRace.
|
|
||||||
///
|
|
||||||
/// Delegates to SkeletonVisuals.SetEquipmentPieceHidden, which scales the wrapper to
|
|
||||||
/// zero and disables its renderers - scale alone leaves a skinned piece (bound to the
|
|
||||||
/// player's own bones rather than its own transform) still drawing, which is what a
|
|
||||||
/// helmet with a skinned cloth or chain part looked like.
|
|
||||||
/// </summary>
|
|
||||||
private static void SetHelmetVisible(VisEquipment visEq, bool visible)
|
|
||||||
{
|
|
||||||
GameObject helmet = Traverse.Create(visEq).Field<GameObject>("m_helmetItemInstance").Value;
|
|
||||||
SkeletonVisuals.SetEquipmentPieceHidden(helmet, !visible);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void HideItemInstances(VisEquipment visEq, string fieldName)
|
private static void HideItemInstances(VisEquipment visEq, string fieldName)
|
||||||
{
|
{
|
||||||
SetItemInstanceActive(visEq, fieldName, false);
|
SetItemInstanceActive(visEq, fieldName, false);
|
||||||
|
|
@ -881,6 +872,10 @@ namespace RacesOfValheim
|
||||||
if (name == "skeleton" ||
|
if (name == "skeleton" ||
|
||||||
name == "skeleton_noarcher" ||
|
name == "skeleton_noarcher" ||
|
||||||
name == "skeleton_poison" ||
|
name == "skeleton_poison" ||
|
||||||
|
name == "skeleton_meadows" || name == "skeleton_meadows_noarcher" ||
|
||||||
|
name == "skeleton_swamps" || name == "skeleton_swamps_noarcher" ||
|
||||||
|
name == "skeleton_mountains" || name == "skeleton_mountains_noarcher" ||
|
||||||
|
name == "skeleton_deepnorth" ||
|
||||||
name == "skeleton_friendly" ||
|
name == "skeleton_friendly" ||
|
||||||
name.StartsWith("draugr") ||
|
name.StartsWith("draugr") ||
|
||||||
name == "ghost" ||
|
name == "ghost" ||
|
||||||
|
|
|
||||||
|
|
@ -125,6 +125,22 @@ namespace RacesOfValheim
|
||||||
Player.m_localPlayer.m_customData["Race"] == "Skeleton";
|
Player.m_localPlayer.m_customData["Race"] == "Skeleton";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Stamina from the tier's stand-in meals, for a Skeleton who feels fatigue but does not
|
||||||
|
/// eat. The fake foods cannot supply it: they are kept at m_time 0, so UpdateFood scales
|
||||||
|
/// their stamina to nothing on every tick.
|
||||||
|
/// </summary>
|
||||||
|
public static float GetStandInStamina(int state)
|
||||||
|
{
|
||||||
|
var foods = GetBestRealFoods(state);
|
||||||
|
float stamina = 0f;
|
||||||
|
if (foods != null)
|
||||||
|
{
|
||||||
|
foreach (var f in foods) stamina += f.m_shared.m_foodStamina;
|
||||||
|
}
|
||||||
|
return stamina;
|
||||||
|
}
|
||||||
|
|
||||||
private static readonly int StatsEffectHash = "SE_SkeletonStats".GetStableHashCode();
|
private static readonly int StatsEffectHash = "SE_SkeletonStats".GetStableHashCode();
|
||||||
|
|
||||||
private float lastAuraTime = 0f;
|
private float lastAuraTime = 0f;
|
||||||
|
|
@ -137,7 +153,7 @@ namespace RacesOfValheim
|
||||||
|
|
||||||
private static List<ItemDrop.ItemData>[] cachedRealFoods = new List<ItemDrop.ItemData>[9];
|
private static List<ItemDrop.ItemData>[] cachedRealFoods = new List<ItemDrop.ItemData>[9];
|
||||||
|
|
||||||
private List<ItemDrop.ItemData> GetBestRealFoods(int state)
|
private static List<ItemDrop.ItemData> GetBestRealFoods(int state)
|
||||||
{
|
{
|
||||||
if (state < 1) state = 1;
|
if (state < 1) state = 1;
|
||||||
if (state > 8) state = 8;
|
if (state > 8) state = 8;
|
||||||
|
|
@ -236,97 +252,6 @@ namespace RacesOfValheim
|
||||||
return bestCombo;
|
return bestCombo;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void DumpTransformHierarchy(Transform t, string indent)
|
|
||||||
{
|
|
||||||
if (t == null) return;
|
|
||||||
Jotunn.Logger.LogInfo(indent + t.name + " (Active: " + t.gameObject.activeSelf + ")");
|
|
||||||
for(int i = 0; i < t.childCount; i++)
|
|
||||||
{
|
|
||||||
DumpTransformHierarchy(t.GetChild(i), indent + " ");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// F8 debug: fires a ray from the camera and logs whatever it hits. Cosmetic pieces
|
|
||||||
/// (hair, beard, helmet) carry no collider, so this mostly confirms terrain/creature hits
|
|
||||||
/// - LogHeadCosmeticsState below is what actually answers "what is that floating chunk."
|
|
||||||
/// Kept anyway because it is the general-purpose "what am I looking at" tool for any other
|
|
||||||
/// bone or prefab placement question that comes up later.
|
|
||||||
/// </summary>
|
|
||||||
private void LogRaycastHit()
|
|
||||||
{
|
|
||||||
Camera cam = Camera.main;
|
|
||||||
if (cam == null)
|
|
||||||
{
|
|
||||||
Jotunn.Logger.LogInfo("[F8] No camera found for raycast.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Ray ray = new Ray(cam.transform.position, cam.transform.forward);
|
|
||||||
if (Physics.Raycast(ray, out RaycastHit hit, 50f))
|
|
||||||
{
|
|
||||||
Jotunn.Logger.LogInfo("--- F8 RAYCAST HIT ---");
|
|
||||||
Jotunn.Logger.LogInfo($"Collider: '{hit.collider.gameObject.name}' at {hit.point:F2}, distance={hit.distance:F2}");
|
|
||||||
Jotunn.Logger.LogInfo($"Full path: {GetFullPath(hit.collider.transform)}");
|
|
||||||
Renderer renderer = hit.collider.GetComponentInParent<Renderer>();
|
|
||||||
if (renderer != null)
|
|
||||||
{
|
|
||||||
Jotunn.Logger.LogInfo($"Nearest renderer: '{renderer.gameObject.name}' ({renderer.GetType().Name}), enabled={renderer.enabled}, scale={renderer.transform.lossyScale:F3}");
|
|
||||||
}
|
|
||||||
Jotunn.Logger.LogInfo("----------------------");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Jotunn.Logger.LogInfo("[F8] Raycast hit nothing within 50m (cosmetic pieces usually have no collider anyway).");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static string GetFullPath(Transform t)
|
|
||||||
{
|
|
||||||
string path = t.name;
|
|
||||||
for (Transform parent = t.parent; parent != null; parent = parent.parent)
|
|
||||||
{
|
|
||||||
path = parent.name + "/" + path;
|
|
||||||
}
|
|
||||||
return path;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// F8 debug: dumps the exact state of the three item slots this race hides (hair, beard,
|
|
||||||
/// helmet) - active flag, renderer enabled flag and scale for every renderer underneath.
|
|
||||||
/// This is the direct answer to "what is still visible and why": a chunk that survives
|
|
||||||
/// hiding will show up here as active=true, or as a renderer with enabled=true even while
|
|
||||||
/// its wrapper is scaled to zero (the skinned-mesh case scale alone cannot hide).
|
|
||||||
/// </summary>
|
|
||||||
private void LogHeadCosmeticsState()
|
|
||||||
{
|
|
||||||
if (Player.m_localPlayer == null) return;
|
|
||||||
VisEquipment vis = Player.m_localPlayer.GetComponent<VisEquipment>();
|
|
||||||
if (vis == null) return;
|
|
||||||
|
|
||||||
Jotunn.Logger.LogInfo("--- F8 SKELETON HEAD COSMETICS ---");
|
|
||||||
DumpItemInstanceField(vis, "m_hairItemInstance");
|
|
||||||
DumpItemInstanceField(vis, "m_beardItemInstance");
|
|
||||||
DumpItemInstanceField(vis, "m_helmetItemInstance");
|
|
||||||
Jotunn.Logger.LogInfo("----------------------------------");
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void DumpItemInstanceField(VisEquipment vis, string fieldName)
|
|
||||||
{
|
|
||||||
GameObject go = HarmonyLib.Traverse.Create(vis).Field<GameObject>(fieldName).Value;
|
|
||||||
if (go == null)
|
|
||||||
{
|
|
||||||
Jotunn.Logger.LogInfo($"[F8] {fieldName}: null (nothing equipped/instantiated).");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Jotunn.Logger.LogInfo($"[F8] {fieldName}: '{go.name}' active={go.activeSelf} scale={go.transform.localScale:F3}");
|
|
||||||
foreach (Renderer r in go.GetComponentsInChildren<Renderer>(true))
|
|
||||||
{
|
|
||||||
Jotunn.Logger.LogInfo($"[F8] renderer '{r.gameObject.name}' ({r.GetType().Name}) enabled={r.enabled}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void Update()
|
private void Update()
|
||||||
{
|
{
|
||||||
if (Player.m_localPlayer == null) return;
|
if (Player.m_localPlayer == null) return;
|
||||||
|
|
@ -396,10 +321,11 @@ namespace RacesOfValheim
|
||||||
{
|
{
|
||||||
// Hide Helmets (Valheim uses singular GameObject for helmet). Only over a skull:
|
// Hide Helmets (Valheim uses singular GameObject for helmet). Only over a skull:
|
||||||
// a viking body wears its helmet, and the VisEquipment postfix puts it back.
|
// a viking body wears its helmet, and the VisEquipment postfix puts it back.
|
||||||
|
// "Show Helmet" keeps it on the skull too, and is published for other clients.
|
||||||
|
SkeletonVisuals.PublishShowHelmet(Player.m_localPlayer);
|
||||||
if (SkeletonConfig.BodyModelEnabled.Value)
|
if (SkeletonConfig.BodyModelEnabled.Value)
|
||||||
{
|
{
|
||||||
var helmetObj = HarmonyLib.Traverse.Create(currentVis).Field<GameObject>("m_helmetItemInstance").Value;
|
SkeletonVisuals.FitHelmet(Player.m_localPlayer, currentVis, SkeletonConfig.ShowHelmet.Value);
|
||||||
SkeletonVisuals.SetEquipmentPieceHidden(helmetObj, true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Scale Body Armor (Chest, Legs, Shoulder) by 5%
|
// Scale Body Armor (Chest, Legs, Shoulder) by 5%
|
||||||
|
|
@ -452,8 +378,15 @@ namespace RacesOfValheim
|
||||||
// Manage Fake Foods
|
// Manage Fake Foods
|
||||||
var foods = Player.m_localPlayer.GetFoods();
|
var foods = Player.m_localPlayer.GetFoods();
|
||||||
bool needsFood = false;
|
bool needsFood = false;
|
||||||
|
|
||||||
if (foods.Count != 3)
|
if (SkeletonConfig.EatsMortalFood.Value)
|
||||||
|
{
|
||||||
|
// Real meals instead. The stand-in foods are the ones held at m_time 0 or below;
|
||||||
|
// dropped here at once rather than left for UpdateFood, which would announce each
|
||||||
|
// one as "food done".
|
||||||
|
foods.RemoveAll(f => f.m_time <= 0f);
|
||||||
|
}
|
||||||
|
else if (foods.Count != 3)
|
||||||
{
|
{
|
||||||
needsFood = true;
|
needsFood = true;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -59,6 +59,41 @@ namespace RacesOfValheim
|
||||||
public static bool ShowsSkeletonBody(Player player) =>
|
public static bool ShowsSkeletonBody(Player player) =>
|
||||||
SkeletonConfig.BodyModelEnabled.Value && IsSkeletonPlayer(player);
|
SkeletonConfig.BodyModelEnabled.Value && IsSkeletonPlayer(player);
|
||||||
|
|
||||||
|
// The owner's "Show Helmet" choice, so every other client draws this skeleton's helmet the
|
||||||
|
// way its owner picked rather than the way the onlooker's own setting says.
|
||||||
|
public const string ShowHelmetZdoKey = "RacesOfValheim_SkeletonShowHelmet";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Whether this skeleton wears its helmet visibly over the skull. The local player and the
|
||||||
|
/// menu preview (which has no ZDO and is always this client's own character) go by this
|
||||||
|
/// client's setting; anyone else by what their owner published.
|
||||||
|
/// </summary>
|
||||||
|
public static bool ShowsHelmet(Player player)
|
||||||
|
{
|
||||||
|
if (player == null) return false;
|
||||||
|
|
||||||
|
ZNetView nview = player.GetComponent<ZNetView>();
|
||||||
|
if (player == Player.m_localPlayer || nview == null || !nview.IsValid())
|
||||||
|
{
|
||||||
|
return SkeletonConfig.ShowHelmet.Value;
|
||||||
|
}
|
||||||
|
|
||||||
|
return nview.GetZDO().GetBool(ShowHelmetZdoKey, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>Writes the local player's choice to its ZDO when it differs. Owner only.</summary>
|
||||||
|
public static void PublishShowHelmet(Player player)
|
||||||
|
{
|
||||||
|
ZNetView nview = player != null ? player.GetComponent<ZNetView>() : null;
|
||||||
|
if (nview == null || !nview.IsValid() || !nview.IsOwner()) return;
|
||||||
|
|
||||||
|
bool show = SkeletonConfig.ShowHelmet.Value;
|
||||||
|
if (nview.GetZDO().GetBool(ShowHelmetZdoKey, false) != show)
|
||||||
|
{
|
||||||
|
nview.GetZDO().Set(ShowHelmetZdoKey, show);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Fully hides (or restores) one equipped item instance - a helmet, typically.
|
/// Fully hides (or restores) one equipped item instance - a helmet, typically.
|
||||||
///
|
///
|
||||||
|
|
@ -71,11 +106,11 @@ namespace RacesOfValheim
|
||||||
/// is reasserted the same way (Valheim's own visual refresh re-enables the instance and
|
/// is reasserted the same way (Valheim's own visual refresh re-enables the instance and
|
||||||
/// resets its scale, so both must be redone every time visuals rebuild).
|
/// resets its scale, so both must be redone every time visuals rebuild).
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static void SetEquipmentPieceHidden(GameObject instance, bool hidden)
|
public static void SetEquipmentPieceHidden(GameObject instance, bool hidden, float shownSize = 1f)
|
||||||
{
|
{
|
||||||
if (instance == null) return;
|
if (instance == null) return;
|
||||||
|
|
||||||
Vector3 wantedScale = hidden ? Vector3.zero : Vector3.one;
|
Vector3 wantedScale = hidden ? Vector3.zero : Vector3.one * shownSize;
|
||||||
if (instance.transform.localScale != wantedScale)
|
if (instance.transform.localScale != wantedScale)
|
||||||
{
|
{
|
||||||
instance.transform.localScale = wantedScale;
|
instance.transform.localScale = wantedScale;
|
||||||
|
|
@ -90,6 +125,218 @@ namespace RacesOfValheim
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Where VisEquipment.AttachItem put the helmet: zero, or the prefab's own "equipoffset".
|
||||||
|
/// Kept on the instance so the fit is always a delta on it, and so taking the fit off
|
||||||
|
/// puts the helmet back exactly. A re-equip makes a new instance without one.
|
||||||
|
/// </summary>
|
||||||
|
private class HelmetBasePose : MonoBehaviour
|
||||||
|
{
|
||||||
|
public Vector3 Position;
|
||||||
|
|
||||||
|
// Skinned parts whose Head bone was swapped for the fit bone, with the bone list
|
||||||
|
// AttachItem gave them, so a viking body gets its own head back.
|
||||||
|
public readonly List<SkinnedMeshRenderer> Fitted = new List<SkinnedMeshRenderer>();
|
||||||
|
public readonly List<Transform[]> OriginalBones = new List<Transform[]>();
|
||||||
|
}
|
||||||
|
|
||||||
|
private const string FitBoneName = "SkeletonHelmetFitBone";
|
||||||
|
|
||||||
|
// The helmet on a skull: metres up and forward, and size. Dialled in on screen with
|
||||||
|
// Configuration Manager sliders (playtest, 2026-10-29) on the bronze, drake and flametal
|
||||||
|
// helmets, then written down here; the sliders are gone. One set fits all three bodies.
|
||||||
|
private const float HelmetFitUp = 0.068f;
|
||||||
|
private const float HelmetFitForward = -0.053f;
|
||||||
|
private const float HelmetFitSize = 1.298f;
|
||||||
|
|
||||||
|
// The same for the fit bone of skinned helmets (the 16 vanilla prefabs with an
|
||||||
|
// "attach_skin" child: hoods, but also Padded, Carapace, Sweatband and others). Tuned on
|
||||||
|
// the Fenring hood, then checked on nearly all the rest (2026-10-29). It scales from the
|
||||||
|
// Head bone's pivot rather than the helmet joint's, hence the different numbers.
|
||||||
|
private const float HoodFitUp = 0.041f;
|
||||||
|
private const float HoodFitForward = -0.071f;
|
||||||
|
private const float HoodFitSize = 1.246f;
|
||||||
|
|
||||||
|
// Which of the helmet joint's own axes are the skull's up and forward. Every player wears
|
||||||
|
// the same rig, so this is found once and kept. Re-picking it every frame made the
|
||||||
|
// offset jump sideways whenever the head turned far enough for another axis to win.
|
||||||
|
private static bool fitAxesFound;
|
||||||
|
private static Vector3 fitUpAxis, fitForwardAxis;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Picks the axes only while the head faces straight ahead, so a turned head on the
|
||||||
|
/// first frame cannot lock in the wrong ones. False until then.
|
||||||
|
/// </summary>
|
||||||
|
private static bool FindFitAxes(Transform joint, Player player)
|
||||||
|
{
|
||||||
|
Vector3 up = ClosestLocalAxis(joint, player.transform.up);
|
||||||
|
Vector3 forward = ClosestLocalAxis(joint, player.transform.forward);
|
||||||
|
if (Vector3.Dot(joint.TransformDirection(up), player.transform.up) < 0.8f ||
|
||||||
|
Vector3.Dot(joint.TransformDirection(forward), player.transform.forward) < 0.8f)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
fitUpAxis = up;
|
||||||
|
fitForwardAxis = forward;
|
||||||
|
fitAxesFound = true;
|
||||||
|
Jotunn.Logger.LogInfo($"[Skeleton] Helmet fit on '{joint.name}': up = local {up}, forward = local {forward}, joint scale {joint.lossyScale}.");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The helmet on a skull: hidden, or shown and moved to fit the skull, which is bigger
|
||||||
|
/// and sits higher and further back than the viking head the helmet hangs for. Hidden
|
||||||
|
/// unless the owner turned on "Show Helmet" (ShowsHelmet).
|
||||||
|
///
|
||||||
|
/// Called from the VisEquipment postfix as well as SkeletonRace and ZdoVisualSync:
|
||||||
|
/// SkeletonRace only ever runs for the local player, which is why the helmet once came
|
||||||
|
/// back on the main-menu preview. The postfix covers the menu, remote players and the
|
||||||
|
/// first frame after a race change.
|
||||||
|
///
|
||||||
|
/// Up and forward are the player's, carried over to whichever of the helmet joint's own
|
||||||
|
/// axes points closest to them. The joint turns with the head, so the helmet keeps its
|
||||||
|
/// place on the skull when the player looks up or down.
|
||||||
|
///
|
||||||
|
/// A hood ("attach_skin") is skinned to the player's own bones, so moving its transform
|
||||||
|
/// does nothing. Its parts weighted to the Head bone get a fit bone instead: a child of
|
||||||
|
/// the real Head carrying the same kind of move and size. The parts weighted to the neck
|
||||||
|
/// and shoulders stay put, so the hood stretches between the two like it would over a
|
||||||
|
/// bigger head. Rigid helmets with a skinned chain or cloth piece get the same treatment
|
||||||
|
/// for that piece.
|
||||||
|
/// </summary>
|
||||||
|
public static void FitHelmet(Player player, VisEquipment vis, bool show)
|
||||||
|
{
|
||||||
|
GameObject helmet = vis != null ? HarmonyLib.Traverse.Create(vis).Field<GameObject>("m_helmetItemInstance").Value : null;
|
||||||
|
if (helmet == null) return;
|
||||||
|
|
||||||
|
if (!show)
|
||||||
|
{
|
||||||
|
SetEquipmentPieceHidden(helmet, true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Always the helmet joint, never the instance's parent: a hood hangs off the body
|
||||||
|
// container, whose axes are not the head's.
|
||||||
|
Transform joint = HarmonyLib.Traverse.Create(vis).Field<Transform>("m_helmet").Value;
|
||||||
|
bool rigid = joint != null && helmet.transform.parent == joint;
|
||||||
|
|
||||||
|
SetEquipmentPieceHidden(helmet, false, rigid ? HelmetFitSize : 1f);
|
||||||
|
|
||||||
|
HelmetBasePose pose = helmet.GetComponent<HelmetBasePose>();
|
||||||
|
if (pose == null)
|
||||||
|
{
|
||||||
|
pose = helmet.AddComponent<HelmetBasePose>();
|
||||||
|
pose.Position = helmet.transform.localPosition;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (joint == null) return;
|
||||||
|
if (!fitAxesFound && !FindFitAxes(joint, player)) return;
|
||||||
|
|
||||||
|
if (rigid)
|
||||||
|
{
|
||||||
|
Vector3 worldOffset = FitOffset(joint, HelmetFitUp, HelmetFitForward);
|
||||||
|
Vector3 wanted = pose.Position + joint.InverseTransformVector(worldOffset);
|
||||||
|
if (helmet.transform.localPosition != wanted)
|
||||||
|
{
|
||||||
|
helmet.transform.localPosition = wanted;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
FitSkinnedParts(player, helmet, pose, joint);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Vector3 FitOffset(Transform joint, float up, float forward) =>
|
||||||
|
joint.TransformDirection(fitUpAxis) * up + joint.TransformDirection(fitForwardAxis) * forward;
|
||||||
|
|
||||||
|
private static readonly HashSet<string> loggedCloth = new HashSet<string>();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Points every skinned part of the helmet that uses the Head bone at this player's fit
|
||||||
|
/// bone, and keeps the fit bone posed. The bone list is the part's own copy (Unity
|
||||||
|
/// copies on get and on set), so the body and the other armour keep the real Head.
|
||||||
|
/// </summary>
|
||||||
|
private static void FitSkinnedParts(Player player, GameObject helmet, HelmetBasePose pose, Transform joint)
|
||||||
|
{
|
||||||
|
Animator anim = player.GetComponentInChildren<Animator>();
|
||||||
|
Transform head = anim != null ? anim.GetBoneTransform(HumanBodyBones.Head) : null;
|
||||||
|
if (head == null) return;
|
||||||
|
|
||||||
|
Transform fitBone = null;
|
||||||
|
foreach (SkinnedMeshRenderer smr in helmet.GetComponentsInChildren<SkinnedMeshRenderer>(true))
|
||||||
|
{
|
||||||
|
if (pose.Fitted.Contains(smr)) continue;
|
||||||
|
|
||||||
|
Transform[] bones = smr.bones;
|
||||||
|
int index = System.Array.IndexOf(bones, head);
|
||||||
|
if (index < 0) continue;
|
||||||
|
|
||||||
|
if (fitBone == null) fitBone = GetFitBone(head);
|
||||||
|
pose.Fitted.Add(smr);
|
||||||
|
pose.OriginalBones.Add((Transform[])bones.Clone());
|
||||||
|
bones[index] = fitBone;
|
||||||
|
smr.bones = bones;
|
||||||
|
|
||||||
|
if (smr.GetComponent<Cloth>() != null && loggedCloth.Add(helmet.name))
|
||||||
|
{
|
||||||
|
Jotunn.Logger.LogInfo($"[Skeleton] Helmet '{helmet.name}': skinned part '{smr.name}' carries Cloth; its Head bone was swapped for the fit bone.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pose.Fitted.Count == 0) return;
|
||||||
|
if (fitBone == null) fitBone = GetFitBone(head);
|
||||||
|
|
||||||
|
Vector3 wantedPos = head.InverseTransformVector(FitOffset(joint, HoodFitUp, HoodFitForward));
|
||||||
|
Vector3 wantedScale = Vector3.one * HoodFitSize;
|
||||||
|
if (fitBone.localPosition != wantedPos) fitBone.localPosition = wantedPos;
|
||||||
|
if (fitBone.localScale != wantedScale) fitBone.localScale = wantedScale;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>This head's fit bone, made the first time a skinned helmet part needs it.</summary>
|
||||||
|
private static Transform GetFitBone(Transform head)
|
||||||
|
{
|
||||||
|
Transform fitBone = head.Find(FitBoneName);
|
||||||
|
if (fitBone != null) return fitBone;
|
||||||
|
|
||||||
|
fitBone = new GameObject(FitBoneName).transform;
|
||||||
|
fitBone.SetParent(head, false);
|
||||||
|
fitBone.localRotation = Quaternion.identity;
|
||||||
|
return fitBone;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>Shows the helmet where vanilla put it, undoing any fit. For a viking body.</summary>
|
||||||
|
public static void UnfitHelmet(VisEquipment vis)
|
||||||
|
{
|
||||||
|
GameObject helmet = vis != null ? HarmonyLib.Traverse.Create(vis).Field<GameObject>("m_helmetItemInstance").Value : null;
|
||||||
|
if (helmet == null) return;
|
||||||
|
|
||||||
|
SetEquipmentPieceHidden(helmet, false);
|
||||||
|
|
||||||
|
HelmetBasePose pose = helmet.GetComponent<HelmetBasePose>();
|
||||||
|
if (pose == null) return;
|
||||||
|
|
||||||
|
if (helmet.transform.localPosition != pose.Position)
|
||||||
|
{
|
||||||
|
helmet.transform.localPosition = pose.Position;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < pose.Fitted.Count; i++)
|
||||||
|
{
|
||||||
|
if (pose.Fitted[i] != null) pose.Fitted[i].bones = pose.OriginalBones[i];
|
||||||
|
}
|
||||||
|
pose.Fitted.Clear();
|
||||||
|
pose.OriginalBones.Clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Vector3 ClosestLocalAxis(Transform joint, Vector3 worldDir)
|
||||||
|
{
|
||||||
|
Vector3 local = joint.InverseTransformDirection(worldDir);
|
||||||
|
Vector3 abs = new Vector3(Mathf.Abs(local.x), Mathf.Abs(local.y), Mathf.Abs(local.z));
|
||||||
|
if (abs.x >= abs.y && abs.x >= abs.z) return new Vector3(Mathf.Sign(local.x), 0f, 0f);
|
||||||
|
if (abs.y >= abs.z) return new Vector3(0f, Mathf.Sign(local.y), 0f);
|
||||||
|
return new Vector3(0f, 0f, Mathf.Sign(local.z));
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The tier a given player's body should be built for. The ZDO carries it so remote
|
/// The tier a given player's body should be built for. The ZDO carries it so remote
|
||||||
/// players render at their own standing; without one - the menu preview - fall back to
|
/// players render at their own standing; without one - the menu preview - fall back to
|
||||||
|
|
|
||||||
|
|
@ -46,6 +46,7 @@ namespace RacesOfValheim
|
||||||
public static ConfigEntry<float> RavagerYawDegrees;
|
public static ConfigEntry<float> RavagerYawDegrees;
|
||||||
public static ConfigEntry<float> RavagerAttackOffsetValue;
|
public static ConfigEntry<float> RavagerAttackOffsetValue;
|
||||||
public static ConfigEntry<bool> RavagerSlamCraterValue;
|
public static ConfigEntry<bool> RavagerSlamCraterValue;
|
||||||
|
public static ConfigEntry<float> RavagerDamageShareValue;
|
||||||
|
|
||||||
// ─── Colony caps ─────────────────────────────────────────────────────
|
// ─── Colony caps ─────────────────────────────────────────────────────
|
||||||
// Every ceiling on how many things the colony can have alive at once, in one section, so
|
// Every ceiling on how many things the colony can have alive at once, in one section, so
|
||||||
|
|
@ -231,6 +232,11 @@ namespace RacesOfValheim
|
||||||
"The middle-click slam digs into the ground where it lands, like a pickaxe blow. " +
|
"The middle-click slam digs into the ground where it lands, like a pickaxe blow. " +
|
||||||
"Never inside a ward you have no access to.");
|
"Never inside a ward you have no access to.");
|
||||||
|
|
||||||
|
RavagerDamageShareValue = config.Bind(ravager, "Ravager Attack Damage", 1f,
|
||||||
|
new ConfigDescription("Share of a real Seeker Brute's damage each Ravager attack deals. " +
|
||||||
|
"Your Unarmed skill then scales it the way it scales a weapon: about 40% at level 0, " +
|
||||||
|
"about 92% at level 100.", new AcceptableValueRange<float>(0.1f, 2f)));
|
||||||
|
|
||||||
EmberGlowStrength = config.Bind(ember, "Glow Strength", SvermConfig.EmberGlowStrength,
|
EmberGlowStrength = config.Bind(ember, "Glow Strength", SvermConfig.EmberGlowStrength,
|
||||||
"How hot the chitin burns at Fader. This multiplies an HDR colour and it is applied " +
|
"How hot the chitin burns at Fader. This multiplies an HDR colour and it is applied " +
|
||||||
"to the chest, the legs and the helmet at once, so it goes a very long way. Settled " +
|
"to the chest, the legs and the helmet at once, so it goes a very long way. Settled " +
|
||||||
|
|
@ -364,6 +370,7 @@ namespace RacesOfValheim
|
||||||
public static float RavagerYaw => RavagerYawDegrees?.Value ?? 0f;
|
public static float RavagerYaw => RavagerYawDegrees?.Value ?? 0f;
|
||||||
public static float RavagerAttackOffset => RavagerAttackOffsetValue?.Value ?? 1.5f;
|
public static float RavagerAttackOffset => RavagerAttackOffsetValue?.Value ?? 1.5f;
|
||||||
public static bool RavagerSlamCrater => RavagerSlamCraterValue?.Value ?? true;
|
public static bool RavagerSlamCrater => RavagerSlamCraterValue?.Value ?? true;
|
||||||
|
public static float RavagerDamageShare => RavagerDamageShareValue?.Value ?? 1f;
|
||||||
|
|
||||||
public static bool Spines => SpinesEnabled?.Value ?? false;
|
public static bool Spines => SpinesEnabled?.Value ?? false;
|
||||||
public static float SizeSmall => SpineSizeSmall?.Value ?? SvermConfig.SpineSizeSmall;
|
public static float SizeSmall => SpineSizeSmall?.Value ?? SvermConfig.SpineSizeSmall;
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,29 @@ namespace RacesOfValheim
|
||||||
{
|
{
|
||||||
public string Trigger;
|
public string Trigger;
|
||||||
public HitData.DamageTypes Damage;
|
public HitData.DamageTypes Damage;
|
||||||
|
|
||||||
|
/// <summary>The Brute weapon itself, for its swing (m_triggerEffect) and impact
|
||||||
|
/// (m_hitEffect) sounds. Vanilla plays both inside Attack, which this form never runs,
|
||||||
|
/// so without them every hit landed silent. Null if the weapon was missing.</summary>
|
||||||
|
public ItemDrop.ItemData.SharedData Shared;
|
||||||
|
|
||||||
|
/// <summary>The weapon's own push (m_attackForce), tool tier and swing arc, the way
|
||||||
|
/// TrolTrueFormModel.Profile carries the troll's.</summary>
|
||||||
|
public float PushForce;
|
||||||
|
public int ToolTier;
|
||||||
|
public float Angle;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// One blow's damage: the Brute's, times Ravager Attack Damage, times the Unarmed skill
|
||||||
|
/// factor the way a weapon's skill scales it (0.25-0.55 at level 0, 0.85-1 at 100).
|
||||||
|
/// TrolTrueFormModel.DamageFor does the same with Clubs for the troll.
|
||||||
|
/// </summary>
|
||||||
|
public static HitData.DamageTypes DamageFor(Player player, Profile profile)
|
||||||
|
{
|
||||||
|
HitData.DamageTypes damage = profile.Damage.Clone();
|
||||||
|
damage.Modify(SvermConfigManagement.RavagerDamageShare * player.GetRandomSkillFactor(Skills.SkillType.Unarmed));
|
||||||
|
return damage;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Profile bite;
|
private static Profile bite;
|
||||||
|
|
@ -72,6 +95,10 @@ namespace RacesOfValheim
|
||||||
{
|
{
|
||||||
Trigger = shared.m_attack != null ? (shared.m_attack.m_attackAnimation ?? "") : "",
|
Trigger = shared.m_attack != null ? (shared.m_attack.m_attackAnimation ?? "") : "",
|
||||||
Damage = shared.m_damages,
|
Damage = shared.m_damages,
|
||||||
|
Shared = shared,
|
||||||
|
PushForce = shared.m_attackForce,
|
||||||
|
ToolTier = shared.m_toolTier,
|
||||||
|
Angle = shared.m_attack != null ? shared.m_attack.m_attackAngle : 90f,
|
||||||
};
|
};
|
||||||
|
|
||||||
Jotunn.Logger.LogInfo($"[Sverm] Ravager Strain reads '{profile.Trigger}' off '{sourcePrefabName}' - " +
|
Jotunn.Logger.LogInfo($"[Sverm] Ravager Strain reads '{profile.Trigger}' off '{sourcePrefabName}' - " +
|
||||||
|
|
|
||||||
|
|
@ -744,7 +744,7 @@ namespace RacesOfValheim
|
||||||
|
|
||||||
wasGrounded = grounded;
|
wasGrounded = grounded;
|
||||||
|
|
||||||
if (!RaceInput.Allowed || !grounded) return;
|
if (!RaceInput.Allowed || !grounded || player.IsStaggering()) return;
|
||||||
|
|
||||||
// Right click rams, left click bites, middle click slams. All three read the device
|
// Right click rams, left click bites, middle click slams. All three read the device
|
||||||
// directly (mouse, or its gamepad counterpart - see RaceInput.AttackDown) rather than
|
// directly (mouse, or its gamepad counterpart - see RaceInput.AttackDown) rather than
|
||||||
|
|
@ -782,6 +782,7 @@ namespace RacesOfValheim
|
||||||
float radius, bool slam, bool lunge)
|
float radius, bool slam, bool lunge)
|
||||||
{
|
{
|
||||||
isAttacking = true;
|
isAttacking = true;
|
||||||
|
FormStagger.MarkAttack();
|
||||||
bool played = StartAttackState(profile);
|
bool played = StartAttackState(profile);
|
||||||
if (rootMotion != null) rootMotion.Active = lunge;
|
if (rootMotion != null) rootMotion.Active = lunge;
|
||||||
|
|
||||||
|
|
@ -791,8 +792,9 @@ namespace RacesOfValheim
|
||||||
|
|
||||||
yield return FollowAttackState(stateName, played, 0f, () =>
|
yield return FollowAttackState(stateName, played, 0f, () =>
|
||||||
{
|
{
|
||||||
|
if (FormStagger.AttackInterrupted) return;
|
||||||
if (slam) Slam(profile, radius, leftY, rightY, dropSamples);
|
if (slam) Slam(profile, radius, leftY, rightY, dropSamples);
|
||||||
else ExecuteDamage(profile, radius);
|
else ExecuteDamage(profile, radius, false);
|
||||||
}, () =>
|
}, () =>
|
||||||
{
|
{
|
||||||
if (leftClaw == null || rightClaw == null) return;
|
if (leftClaw == null || rightClaw == null) return;
|
||||||
|
|
@ -826,7 +828,11 @@ namespace RacesOfValheim
|
||||||
{
|
{
|
||||||
Player player = Player.m_localPlayer;
|
Player player = Player.m_localPlayer;
|
||||||
if (player != null)
|
if (player != null)
|
||||||
ApplyDamageInSphere(player.transform.position + Vector3.up, SvermConfig.RavagerTauntRadius, profile.Damage);
|
{
|
||||||
|
// No Strike: the roar above is the taunt's sound, the weapon's would double it.
|
||||||
|
if (ApplyDamageInSphere(player.transform.position + Vector3.up, SvermConfig.RavagerTauntRadius, profile, true))
|
||||||
|
FormMelee.RaiseSkill(Skills.SkillType.Unarmed);
|
||||||
|
}
|
||||||
}, null);
|
}, null);
|
||||||
|
|
||||||
isAttacking = false;
|
isAttacking = false;
|
||||||
|
|
@ -842,6 +848,11 @@ namespace RacesOfValheim
|
||||||
{
|
{
|
||||||
if (hasForwardSpeed) anim.SetFloat("forward_speed", 0f);
|
if (hasForwardSpeed) anim.SetFloat("forward_speed", 0f);
|
||||||
|
|
||||||
|
// The Brute weapon's swing sound, which vanilla plays in Attack.Start (the bite's
|
||||||
|
// snap, the ram's charge, the slam's wind-up). The taunt's weapon has none.
|
||||||
|
Player player = Player.m_localPlayer;
|
||||||
|
if (player != null) profile.Shared?.m_startEffect.Create(player.transform.position, player.transform.rotation, player.transform);
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(profile.Trigger) || !knownTriggers.Contains(profile.Trigger)) return false;
|
if (string.IsNullOrEmpty(profile.Trigger) || !knownTriggers.Contains(profile.Trigger)) return false;
|
||||||
|
|
||||||
anim.SetTrigger(profile.Trigger);
|
anim.SetTrigger(profile.Trigger);
|
||||||
|
|
@ -942,14 +953,14 @@ namespace RacesOfValheim
|
||||||
Transform claw = StrikingClaw(leftY, rightY, samples);
|
Transform claw = StrikingClaw(leftY, rightY, samples);
|
||||||
if (claw == null)
|
if (claw == null)
|
||||||
{
|
{
|
||||||
ExecuteDamage(profile, radius);
|
ExecuteDamage(profile, radius, true);
|
||||||
Player player = Player.m_localPlayer;
|
Player player = Player.m_localPlayer;
|
||||||
if (player != null)
|
if (player != null)
|
||||||
DigCrater(player.transform.position + player.transform.forward * SvermConfigManagement.RavagerAttackOffset);
|
DigCrater(player.transform.position + player.transform.forward * SvermConfigManagement.RavagerAttackOffset);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ApplyDamageInSphere(claw.position + Vector3.up * 0.5f, radius, profile.Damage);
|
Strike(claw.position + Vector3.up * 0.5f, radius, profile, true);
|
||||||
DigCrater(claw.position);
|
DigCrater(claw.position);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -983,14 +994,14 @@ namespace RacesOfValheim
|
||||||
/// FenrirBehaviors.ExecuteClawDamage, unchanged in shape: a sphere swept against the same
|
/// FenrirBehaviors.ExecuteClawDamage, unchanged in shape: a sphere swept against the same
|
||||||
/// broad layer mask every melee form in this mod already uses.
|
/// broad layer mask every melee form in this mod already uses.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private void ExecuteDamage(SvermRavagerAttacks.Profile profile, float radius)
|
private void ExecuteDamage(SvermRavagerAttacks.Profile profile, float radius, bool slam)
|
||||||
{
|
{
|
||||||
Player player = Player.m_localPlayer;
|
Player player = Player.m_localPlayer;
|
||||||
if (player == null) return;
|
if (player == null) return;
|
||||||
|
|
||||||
float reach = SvermConfigManagement.RavagerAttackOffset;
|
float reach = SvermConfigManagement.RavagerAttackOffset;
|
||||||
Vector3 attackPoint = player.transform.position + player.transform.forward * reach + Vector3.up;
|
Vector3 attackPoint = player.transform.position + player.transform.forward * reach + Vector3.up;
|
||||||
ApplyDamageInSphere(attackPoint, radius, profile.Damage);
|
Strike(attackPoint, radius, profile, slam);
|
||||||
}
|
}
|
||||||
|
|
||||||
private const string CraterPrefab = "digg_v3";
|
private const string CraterPrefab = "digg_v3";
|
||||||
|
|
@ -1013,26 +1024,40 @@ namespace RacesOfValheim
|
||||||
if (crater != null) Object.Instantiate(crater, ground.point, Quaternion.identity);
|
if (crater != null) Object.Instantiate(crater, ground.point, Quaternion.identity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private const string FormLabel = "Ravager";
|
||||||
|
|
||||||
|
private static readonly int HitMask = LayerMask.GetMask("Default", "static_solid", "Default_small", "piece",
|
||||||
|
"piece_nonsolid", "terrain", "character", "character_net", "character_ghost",
|
||||||
|
"hitbox", "character_noenv", "vehicle");
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The actual sweep, shared by every attack this form has (the three forward swings and
|
/// The actual sweep, shared by every attack this form has. TrolTrueFormHit.SphereHit in
|
||||||
/// the taunt's own AoE) - only the sphere's centre and radius differ between them.
|
/// shape: a forward swing stays inside its arc (the Brute's own, widened to 75 degrees each
|
||||||
|
/// side the way the troll's is), the slam's claws and the taunt reach all around, and
|
||||||
|
/// FormMelee.CanReach keeps a blow from landing through a wall. Each target that takes the
|
||||||
|
/// blow plays the Brute weapon's own impact effect, which vanilla plays inside Attack.
|
||||||
///
|
///
|
||||||
/// m_skill is Swords, deliberately NOT Unarmed: Sverm_Damage_Patch rewrites any Unarmed
|
/// m_skill is Swords, deliberately NOT Unarmed: Sverm_Damage_Patch rewrites any Unarmed
|
||||||
/// hit from a Sverm into the Chitin Claws' own tier damage, and that patch fires for THIS
|
/// hit from a Sverm into the Chitin Claws' own tier damage, and that patch fires for THIS
|
||||||
/// call too, since it hooks Character.Damage itself rather than caring who dealt the hit.
|
/// call too, since it hooks Character.Damage itself rather than caring who dealt the hit.
|
||||||
/// Swords keeps that rewrite from overwriting the Brute's real numbers with the claws'.
|
/// Swords keeps that rewrite from overwriting the Brute's numbers with the claws'. It is
|
||||||
|
/// the Brute weapons' own skill too. The damage still scales with Unarmed (DamageFor).
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private static void ApplyDamageInSphere(Vector3 center, float radius, HitData.DamageTypes damage)
|
/// <returns>True if the blow landed on a creature, so the caller raises the skill.</returns>
|
||||||
|
private static bool ApplyDamageInSphere(Vector3 center, float radius, SvermRavagerAttacks.Profile profile, bool allAround)
|
||||||
{
|
{
|
||||||
Player player = Player.m_localPlayer;
|
Player player = Player.m_localPlayer;
|
||||||
if (player == null) return;
|
if (player == null) return false;
|
||||||
|
|
||||||
int layerMask = LayerMask.GetMask("Default", "static_solid", "Default_small", "piece",
|
Vector3 pos = player.transform.position;
|
||||||
"piece_nonsolid", "terrain", "character", "character_net", "character_ghost",
|
Vector3 forward = player.transform.forward;
|
||||||
"hitbox", "character_noenv", "vehicle");
|
float halfAngle = allAround ? 180f : Mathf.Max(75f, profile.Angle * 0.5f);
|
||||||
|
HitData.DamageTypes damage = SvermRavagerAttacks.DamageFor(player, profile);
|
||||||
|
|
||||||
Collider[] hits = Physics.OverlapSphere(center, radius, layerMask);
|
Collider[] hits = Physics.OverlapSphere(center, radius, HitMask);
|
||||||
|
FormMelee.LogSwing(FormLabel, hits.Length);
|
||||||
var hitObjects = new System.Collections.Generic.HashSet<GameObject>();
|
var hitObjects = new System.Collections.Generic.HashSet<GameObject>();
|
||||||
|
bool hitCreature = false;
|
||||||
|
|
||||||
foreach (Collider hit in hits)
|
foreach (Collider hit in hits)
|
||||||
{
|
{
|
||||||
|
|
@ -1040,34 +1065,65 @@ namespace RacesOfValheim
|
||||||
if (hit.attachedRigidbody != null && hit.attachedRigidbody.gameObject == player.gameObject) continue;
|
if (hit.attachedRigidbody != null && hit.attachedRigidbody.gameObject == player.gameObject) continue;
|
||||||
|
|
||||||
IDestructible target = hit.GetComponentInParent<IDestructible>();
|
IDestructible target = hit.GetComponentInParent<IDestructible>();
|
||||||
if (target == null) continue;
|
if (target == null || (target is Character self && self == player)) continue;
|
||||||
|
|
||||||
if (target is Character characterTarget && characterTarget == player) continue;
|
|
||||||
|
|
||||||
|
// Marked only once it is hit, further down, so a limb outside the arc does not rule
|
||||||
|
// out a body squarely in the swing.
|
||||||
GameObject targetObj = (target as MonoBehaviour)?.gameObject;
|
GameObject targetObj = (target as MonoBehaviour)?.gameObject;
|
||||||
if (targetObj != null)
|
if (targetObj != null && hitObjects.Contains(targetObj)) continue;
|
||||||
{
|
|
||||||
if (hitObjects.Contains(targetObj)) continue;
|
|
||||||
hitObjects.Add(targetObj);
|
|
||||||
}
|
|
||||||
|
|
||||||
Vector3 targetCenter = hit.bounds.center;
|
Vector3 targetCenter = hit.bounds.center;
|
||||||
Vector3 dirToTarget = (targetCenter - player.transform.position).normalized;
|
Vector3 flat = targetCenter - pos;
|
||||||
|
flat.y = 0f;
|
||||||
|
float angle = flat.sqrMagnitude > 0.0001f ? Vector3.Angle(forward, flat) : 0f;
|
||||||
|
if (angle > halfAngle)
|
||||||
|
{
|
||||||
|
FormMelee.LogMiss(FormLabel, hit, $"outside the swing arc ({angle:0} deg)");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!FormMelee.CanReach(player.GetEyePoint(), center, hit, target, out string cover))
|
||||||
|
{
|
||||||
|
FormMelee.LogMiss(FormLabel, hit, "no clear line, blocked by '" + cover + "'");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
HitData hitData = new HitData();
|
HitData hitData = new HitData();
|
||||||
hitData.m_damage = damage;
|
hitData.m_damage = damage;
|
||||||
hitData.m_point = targetCenter;
|
hitData.m_point = targetCenter;
|
||||||
hitData.m_dir = dirToTarget;
|
hitData.m_dir = (targetCenter - pos).normalized;
|
||||||
hitData.m_pushForce = 40f;
|
hitData.m_pushForce = profile.PushForce;
|
||||||
hitData.m_skill = Skills.SkillType.Swords;
|
hitData.m_skill = Skills.SkillType.Swords;
|
||||||
hitData.m_dodgeable = true;
|
hitData.m_dodgeable = true;
|
||||||
hitData.m_blockable = true;
|
hitData.m_blockable = true;
|
||||||
hitData.m_hitType = HitData.HitType.PlayerHit;
|
hitData.m_hitType = HitData.HitType.PlayerHit;
|
||||||
hitData.m_toolTier = 100;
|
hitData.m_toolTier = (short)profile.ToolTier;
|
||||||
hitData.SetAttacker(player);
|
hitData.SetAttacker(player);
|
||||||
|
|
||||||
|
if (targetObj != null) hitObjects.Add(targetObj);
|
||||||
|
FormMelee.LogHit(FormLabel, target, damage.GetTotalDamage());
|
||||||
target.Damage(hitData);
|
target.Damage(hitData);
|
||||||
|
FormMelee.GrantAdrenaline(target);
|
||||||
|
profile.Shared?.m_hitEffect.Create(targetCenter, Quaternion.identity);
|
||||||
|
if (target is Character) hitCreature = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return hitCreature;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// One blow of a Ravager attack: the Brute weapon's trigger effect (the slam's landing
|
||||||
|
/// thud; the bite and the ram have none), the sweep, and the Unarmed experience vanilla
|
||||||
|
/// pays inside Attack for a swing that reached a creature. The Ravager fights unarmed like
|
||||||
|
/// the rest of the Sverm, so that is the skill it trains.
|
||||||
|
/// </summary>
|
||||||
|
private static void Strike(Vector3 center, float radius, SvermRavagerAttacks.Profile profile, bool allAround)
|
||||||
|
{
|
||||||
|
Player player = Player.m_localPlayer;
|
||||||
|
if (player == null) return;
|
||||||
|
|
||||||
|
profile.Shared?.m_triggerEffect.Create(center, player.transform.rotation);
|
||||||
|
if (ApplyDamageInSphere(center, radius, profile, allAround)) FormMelee.RaiseSkill(Skills.SkillType.Unarmed);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||