1.0 compatibility
This commit is contained in:
parent
5104f86ede
commit
6193b3ee2d
33 changed files with 712 additions and 49 deletions
182
JotunnModStub/Aswid/AswidBatAggro.cs
Normal file
182
JotunnModStub/Aswid/AswidBatAggro.cs
Normal file
|
|
@ -0,0 +1,182 @@
|
|||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
57
JotunnModStub/Aswid/AswidBatFlight.cs
Normal file
57
JotunnModStub/Aswid/AswidBatFlight.cs
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -33,6 +33,14 @@ namespace RacesOfValheim
|
|||
public static ConfigEntry<float> BloodMagicSkillGainMultiplier;
|
||||
public static ConfigEntry<float> SurtlingFormDamageBonus;
|
||||
|
||||
// ─── Bat Form ────────────────────────────────────────────────────────────
|
||||
// Both of these undo something vanilla does to any player on the debug-fly flag, which is
|
||||
// what the bat flies on. See AswidBatAggro for the six vanilla methods involved.
|
||||
public static ConfigEntry<bool> BatFormAggro;
|
||||
public static ConfigEntry<bool> BatFormVulnerable;
|
||||
// A factor on vanilla's debug-fly speed, not a speed in metres - see AswidBatFlight.
|
||||
public static ConfigEntry<float> BatFormFlightSpeed;
|
||||
|
||||
// ─── Vampiric Aura (passive, always active) ──────────────────────────────
|
||||
public static ConfigEntry<float> AuraTickInterval;
|
||||
public static ConfigEntry<float> AuraRadiusDay;
|
||||
|
|
@ -122,6 +130,14 @@ namespace RacesOfValheim
|
|||
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)));
|
||||
|
||||
const string batform = "Aswid - Bat Form";
|
||||
BatFormAggro = config.Bind(batform, "Monsters Notice The Bat", true,
|
||||
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."));
|
||||
BatFormVulnerable = config.Bind(batform, "The Bat Can Be Hurt", true,
|
||||
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."));
|
||||
BatFormFlightSpeed = config.Bind(batform, "Flight Speed", 1f,
|
||||
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)));
|
||||
|
||||
const string aura = "Aswid - Vampiric Aura";
|
||||
AuraTickInterval = config.Bind(aura, "Tick Interval", 0.25f,
|
||||
new ConfigDescription("Seconds between aura damage/lifesteal ticks.", new AcceptableValueRange<float>(0.05f, 2f)));
|
||||
|
|
|
|||
|
|
@ -53,7 +53,9 @@ namespace RacesOfValheim
|
|||
|
||||
|
||||
|
||||
[HarmonyPatch(typeof(SEMan), "AddStatusEffect", new System.Type[] { typeof(int), typeof(bool), typeof(int), typeof(float) })]
|
||||
// Valheim 1.0 appended a 'short variant' parameter to this overload. The type array has to
|
||||
// match it exactly or the patch silently fails to bind and PatchAll throws.
|
||||
[HarmonyPatch(typeof(SEMan), "AddStatusEffect", new System.Type[] { typeof(int), typeof(bool), typeof(int), typeof(float), typeof(short) })]
|
||||
public static class AswidSEManPatch
|
||||
{
|
||||
public static bool Prefix(SEMan __instance, ref int nameHash)
|
||||
|
|
|
|||
|
|
@ -416,6 +416,17 @@ namespace RacesOfValheim
|
|||
{
|
||||
StartCoroutine(RevertMistFormRoutine());
|
||||
}
|
||||
|
||||
// Same rule for a night-only bat: a form the sun forbids cannot be kept through the
|
||||
// sunrise, or the daylight gate above would only be one night's patience away from
|
||||
// meaningless. activeRules is what the transform was actually granted under, so an
|
||||
// Aswid who has killed The Elder (NeedsNight false) keeps flying into the morning.
|
||||
if (IsTransformed && !isTransformingSequence && activeRules != null && activeRules.NeedsNight &&
|
||||
EnvMan.instance != null && EnvMan.IsDay())
|
||||
{
|
||||
Player.m_localPlayer.Message(MessageHud.MessageType.Center, "The morning sun drives the bat back into your body");
|
||||
StartCoroutine(RevertToHumanRoutine());
|
||||
}
|
||||
}
|
||||
|
||||
private string DumpGameObject(GameObject go, string indent)
|
||||
|
|
@ -509,6 +520,17 @@ namespace RacesOfValheim
|
|||
return;
|
||||
}
|
||||
|
||||
// The night gate lives here, not in GetGKeyRules: the rules only say WHETHER night is
|
||||
// required (state 2, Eikthyr) or not (state 3+, The Elder). Nothing ever read the
|
||||
// NeedsNight flag, so an Aswid who had only killed Eikthyr could turn into a bat in
|
||||
// broad daylight. Placed after the revert branch on purpose - a bat caught by the
|
||||
// sunrise must always be able to turn back.
|
||||
if (rules.NeedsNight && (EnvMan.instance == null || !EnvMan.IsNight()))
|
||||
{
|
||||
Player.m_localPlayer.Message(MessageHud.MessageType.Center, "The sun burns. You can only take bat form at night.");
|
||||
return;
|
||||
}
|
||||
|
||||
StartCoroutine(TransformIntoBatRoutine(rules));
|
||||
}
|
||||
|
||||
|
|
@ -524,6 +546,49 @@ namespace RacesOfValheim
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Everything RevertToHumanRoutine does, minus the puff of smoke and the scale animation,
|
||||
/// and without a coroutine - because the one moment this exists for is death, and by then
|
||||
/// Update() has already bailed out on IsDead(), so a coroutine started here would be the
|
||||
/// only thing still running on a corpse.
|
||||
///
|
||||
/// Leaving the form up costs more than a missing animation: m_debugFly stays on, so the
|
||||
/// 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
|
||||
/// stays on the transform. Called from Aswid_BatDiesAsBat_Patch.
|
||||
/// </summary>
|
||||
public void HardResetBatForm()
|
||||
{
|
||||
Player player = Player.m_localPlayer;
|
||||
if (player == null) return;
|
||||
if (!IsTransformed && !isTransformingSequence) return;
|
||||
|
||||
if (currentTransformation != null)
|
||||
{
|
||||
Destroy(currentTransformation);
|
||||
currentTransformation = null;
|
||||
}
|
||||
|
||||
PlayerVisualHider.Show(player.transform.Find("Visual"), "aswid-bat-death-reset");
|
||||
|
||||
if (player.GetSEMan() != null)
|
||||
player.GetSEMan().RemoveStatusEffect("SE_BatForm".GetStableHashCode(), true);
|
||||
|
||||
ZNetView nview = player.GetComponent<ZNetView>();
|
||||
if (nview != null && nview.IsValid())
|
||||
{
|
||||
nview.GetZDO().Set("Aswid_IsBatForm", false);
|
||||
nview.GetZDO().Set(ZDOVars.s_debugFly, false);
|
||||
}
|
||||
Traverse.Create(player).Field("m_debugFly").SetValue(false);
|
||||
|
||||
player.transform.localScale = Vector3.one;
|
||||
|
||||
IsTransformed = false;
|
||||
activeRules = null;
|
||||
isTransformingSequence = false;
|
||||
}
|
||||
|
||||
private System.Collections.IEnumerator TransformIntoBatRoutine(AswidProgression.FormRules rules)
|
||||
{
|
||||
isTransformingSequence = true;
|
||||
|
|
@ -961,7 +1026,7 @@ namespace RacesOfValheim
|
|||
|
||||
// Create an invisible virtual inventory so the food never goes to the real bag
|
||||
Inventory virtualInv = new Inventory("AswidStomach", null, 1, 1);
|
||||
ItemDrop.ItemData addedItem = virtualInv.AddItem(foodPrefab.name, 1, 1, 0, 0, "");
|
||||
ItemDrop.ItemData addedItem = virtualInv.AddItem(foodPrefab.name, 1, 1, 0, 0, "", false);
|
||||
|
||||
if (addedItem != null)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -151,6 +151,10 @@ namespace RacesOfValheim
|
|||
}
|
||||
}
|
||||
|
||||
// New in Valheim 1.0: Hoverable gained this. Every vanilla implementation returns a
|
||||
// serialised m_hoverOffset, which is 0 unless the prefab sets one, so 0 is vanilla behaviour.
|
||||
public float GetHoverOffset() => 0f;
|
||||
|
||||
public string GetHoverName()
|
||||
{
|
||||
return ""; // Character component already provides the name
|
||||
|
|
|
|||
|
|
@ -1,10 +1,29 @@
|
|||
using HarmonyLib;
|
||||
using UnityEngine;
|
||||
using Jotunn.Managers;
|
||||
|
||||
namespace RacesOfValheim
|
||||
{
|
||||
/// <summary>
|
||||
/// 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
|
||||
/// what the local player's own physics reads; ZDOVars.s_debugFly is what every OTHER client
|
||||
/// reads, because Character.IsDebugFlying consults the ZDO whenever it is not the owner. With
|
||||
/// only the field written, a bat flew on its own screen and fell, walked and swam on everyone
|
||||
/// else's - the fault WarVultureMount.SetFlying already names in its own summary. Both halves
|
||||
/// 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
|
||||
/// ZDOExtraData.Set, which returns false when the value is unchanged, and only a true return
|
||||
/// bumps the data revision. Read out of the assembly rather than assumed, because "every frame"
|
||||
/// deserved the check.
|
||||
/// </summary>
|
||||
public class BatFormBehavior : MonoBehaviour
|
||||
{
|
||||
private static readonly System.Reflection.FieldInfo DebugFlyField =
|
||||
AccessTools.Field(typeof(Player), "m_debugFly");
|
||||
|
||||
private Animator anim;
|
||||
private AswidProgression.FormRules formRules;
|
||||
|
||||
|
|
@ -16,10 +35,7 @@ namespace RacesOfValheim
|
|||
private void Start()
|
||||
{
|
||||
anim = GetComponentInChildren<Animator>();
|
||||
if (Player.m_localPlayer != null)
|
||||
{
|
||||
HarmonyLib.Traverse.Create(Player.m_localPlayer).Field("m_debugFly").SetValue(true);
|
||||
}
|
||||
SetFlying(true);
|
||||
}
|
||||
|
||||
private void Update()
|
||||
|
|
@ -27,7 +43,7 @@ namespace RacesOfValheim
|
|||
if (Player.m_localPlayer == null || Player.m_localPlayer.IsDead()) return;
|
||||
|
||||
// Ensure flight remains on continuously
|
||||
HarmonyLib.Traverse.Create(Player.m_localPlayer).Field("m_debugFly").SetValue(true);
|
||||
SetFlying(true);
|
||||
|
||||
// Sync Animator
|
||||
if (anim != null)
|
||||
|
|
@ -35,7 +51,7 @@ namespace RacesOfValheim
|
|||
Vector3 vel = Player.m_localPlayer.GetVelocity();
|
||||
vel.y = 0f;
|
||||
float 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);
|
||||
|
|
@ -45,9 +61,25 @@ namespace RacesOfValheim
|
|||
|
||||
private void OnDestroy()
|
||||
{
|
||||
if (Player.m_localPlayer != null)
|
||||
SetFlying(false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Both halves of debug fly, always together. The field write survives a missing or invalid
|
||||
/// ZNetView on purpose: without it a bat whose networking went away mid-flight would keep
|
||||
/// flying on foot forever, which is the worse of the two failures.
|
||||
/// </summary>
|
||||
private static void SetFlying(bool flying)
|
||||
{
|
||||
Player player = Player.m_localPlayer;
|
||||
if (player == null) return;
|
||||
|
||||
if (DebugFlyField != null) DebugFlyField.SetValue(player, flying);
|
||||
|
||||
ZNetView nview = player.GetComponent<ZNetView>();
|
||||
if (nview != null && nview.IsValid() && nview.IsOwner())
|
||||
{
|
||||
HarmonyLib.Traverse.Create(Player.m_localPlayer).Field("m_debugFly").SetValue(false);
|
||||
nview.GetZDO().Set(ZDOVars.s_debugFly, flying);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -95,6 +95,36 @@ namespace RacesOfValheim
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Whether this character carries a claimed personal tier at all. Distinct from
|
||||
/// "PersonalState == MinState": the getter answers MinState for a character who has never
|
||||
/// claimed anything AND for one who has been reset, and the Reset Progression button needs
|
||||
/// to tell the player which of the two just happened.
|
||||
/// </summary>
|
||||
public static bool HasPersonalState
|
||||
{
|
||||
get
|
||||
{
|
||||
Player player = Player.m_localPlayer;
|
||||
if (player == null || player.m_customData == null) return false;
|
||||
return player.m_customData.ContainsKey(PersonalStateKey);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gives back every tier claimed with a boss relic. The key is removed rather than written
|
||||
/// back as MinState so the character reads as one that never claimed anything - which is
|
||||
/// what a reset means, and what HasPersonalState above then reports.
|
||||
///
|
||||
/// The relics themselves do not come back: RaceMenuWardBehavior.UseItem consumed them.
|
||||
/// </summary>
|
||||
public static void ClearPersonalState()
|
||||
{
|
||||
Player player = Player.m_localPlayer;
|
||||
if (player == null || player.m_customData == null) return;
|
||||
player.m_customData.Remove(PersonalStateKey);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the current progression state of the world based on defeated bosses.
|
||||
/// 1 = No bosses defeated
|
||||
|
|
|
|||
|
|
@ -400,8 +400,10 @@ namespace RacesOfValheim
|
|||
/// The same shape as TrolTotemRaceLockPatch - the second station in the mod that refuses the hammer
|
||||
/// outright, because hiring dvergr with dvergr money is the race's identity and not a tool it owns.
|
||||
/// </summary>
|
||||
// Valheim 1.0 appended a 'bool cheated' parameter to this overload. The type array has to
|
||||
// match it exactly or the patch silently fails to bind and PatchAll throws.
|
||||
[HarmonyPatch(typeof(Player), "PlacePiece",
|
||||
new[] { typeof(Piece), typeof(Vector3), typeof(Quaternion), typeof(bool) })]
|
||||
new[] { typeof(Piece), typeof(Vector3), typeof(Quaternion), typeof(bool), typeof(bool) })]
|
||||
public static class DvergarBancoRaceLockPatch
|
||||
{
|
||||
public static bool Prefix(Player __instance, Piece __0)
|
||||
|
|
|
|||
|
|
@ -192,8 +192,10 @@ namespace RacesOfValheim
|
|||
}
|
||||
}
|
||||
|
||||
// Valheim 1.0 appended a 'bool cheated' parameter to this overload. The type array has to
|
||||
// match it exactly or the patch silently fails to bind and PatchAll throws.
|
||||
[HarmonyPatch(typeof(Player), "PlacePiece",
|
||||
new[] { typeof(Piece), typeof(Vector3), typeof(Quaternion), typeof(bool) })]
|
||||
new[] { typeof(Piece), typeof(Vector3), typeof(Quaternion), typeof(bool), typeof(bool) })]
|
||||
public static class DvergarBotteRaceLockPatch
|
||||
{
|
||||
public static bool Prefix(Player __instance, Piece __0)
|
||||
|
|
|
|||
|
|
@ -169,7 +169,7 @@ namespace RacesOfValheim
|
|||
|
||||
int coinsEarned = entry.Price * sold;
|
||||
GameObject coinPrefab = ((Component)gui.m_coinPrefab).gameObject;
|
||||
inv.AddItem(coinPrefab.name, coinsEarned, gui.m_coinPrefab.m_itemData.m_quality, gui.m_coinPrefab.m_itemData.m_variant, 0L, "");
|
||||
inv.AddItem(coinPrefab.name, coinsEarned, gui.m_coinPrefab.m_itemData.m_quality, gui.m_coinPrefab.m_itemData.m_variant, 0L, "", false);
|
||||
|
||||
Trader trader = FactionMerchantRuntime.GetActiveTrader(gui);
|
||||
trader?.OnSold();
|
||||
|
|
|
|||
|
|
@ -93,8 +93,10 @@ namespace RacesOfValheim
|
|||
}
|
||||
|
||||
// ─── Block external Burning (fire pits, arrows) from being applied ────
|
||||
// Valheim 1.0 appended a 'short variant' parameter to this overload. The type array has to
|
||||
// match it exactly or the patch silently fails to bind and PatchAll throws.
|
||||
[HarmonyPatch(typeof(SEMan), "AddStatusEffect",
|
||||
new System.Type[] { typeof(int), typeof(bool), typeof(int), typeof(float) })]
|
||||
new System.Type[] { typeof(int), typeof(bool), typeof(int), typeof(float), typeof(short) })]
|
||||
public static class FurlingFire_SuppressExternalBurning_Patch
|
||||
{
|
||||
public static bool AllowNextBurning = false;
|
||||
|
|
|
|||
|
|
@ -445,7 +445,7 @@ namespace RacesOfValheim
|
|||
int quality = craftUpgradeItem != null ? craftUpgradeItem.m_quality + 1 : 1;
|
||||
int craftVariant = HarmonyLib.Traverse.Create(__instance).Field("m_craftVariant").GetValue<int>();
|
||||
|
||||
ItemDrop.ItemData addedItem = player.GetInventory().AddItem(itemDrop.gameObject.name, amount, quality, craftVariant, player.GetPlayerID(), player.GetPlayerName());
|
||||
ItemDrop.ItemData addedItem = player.GetInventory().AddItem(itemDrop.gameObject.name, amount, quality, craftVariant, player.GetPlayerID(), player.GetPlayerName(), false);
|
||||
|
||||
if (addedItem == null)
|
||||
{
|
||||
|
|
|
|||
57
JotunnModStub/MaterialManPropertyBlockFix.cs
Normal file
57
JotunnModStub/MaterialManPropertyBlockFix.cs
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
using System.Reflection;
|
||||
using HarmonyLib;
|
||||
using UnityEngine;
|
||||
|
||||
namespace RacesOfValheim
|
||||
{
|
||||
/// <summary>
|
||||
/// Closes the window in Valheim 1.0 where MaterialMan hands out a null property block.
|
||||
///
|
||||
/// MaterialMan splits its own start-up across two Unity callbacks:
|
||||
///
|
||||
/// Awake() -> s_instance = this
|
||||
/// Start() -> m_propertyBlock = new MaterialPropertyBlock()
|
||||
///
|
||||
/// Between the two, MaterialMan.instance answers but its property block is still null. Anything
|
||||
/// that registers with it in that gap gets a PropertyContainer built around that null - and the
|
||||
/// container KEEPS it, because it copies the reference into a field of its own rather than
|
||||
/// reading MaterialMan's each frame. UpdateBlock() opens with m_propertyBlock.Clear(), so that
|
||||
/// one container then throws a NullReferenceException on every frame for the rest of the scene.
|
||||
/// A single session logged 463 of them, all identical, all from MaterialMan.UpdateBlock.
|
||||
///
|
||||
/// This is vanilla's bug, not ours, but 1.0 is what made us walk into it: VisEquipment.AttachArmor
|
||||
/// and AttachItem now call RefreshSnowLevel, which registers with MaterialMan, and none of that
|
||||
/// existed in 0.221. Comparing the two builds, the snow-cover system is the ONLY new caller of
|
||||
/// MaterialMan - so a mod that dresses the main-menu preview, as this one does for every race,
|
||||
/// reaches it during the gap where before there was nothing to reach.
|
||||
///
|
||||
/// Filling the block in Awake costs one allocation, once per scene, and removes the gap: whoever
|
||||
/// registers early now gets a real block. Start() still makes its own a moment later and every
|
||||
/// container built after that point uses that one instead, which is fine - UpdateBlock clears and
|
||||
/// refills the block before each renderer reads it, so a container holding a different instance
|
||||
/// behaves identically. Vanilla is otherwise left alone.
|
||||
///
|
||||
/// The symptom was only ever visible on the main menu, because loading a world builds a fresh
|
||||
/// MaterialMan whose Start has long since run. It was never a gameplay bug - just 463 lines of
|
||||
/// noise standing between us and the log entries that matter.
|
||||
/// </summary>
|
||||
[HarmonyPatch(typeof(MaterialMan), "Awake")]
|
||||
internal static class MaterialManPropertyBlockFix
|
||||
{
|
||||
/// <summary>Private in the shipped assembly, so it is reached by reflection like the rest.</summary>
|
||||
private static readonly FieldInfo PropertyBlock = AccessTools.Field(typeof(MaterialMan), "m_propertyBlock");
|
||||
|
||||
/// <summary>If a future build renames or removes the field, patch nothing rather than guess.</summary>
|
||||
private static bool Prepare() => PropertyBlock != null;
|
||||
|
||||
private static void Postfix(MaterialMan __instance)
|
||||
{
|
||||
// Awake destroys itself when another instance already claimed s_instance. Writing to a
|
||||
// component on its way out is harmless, and testing for it would cost more than it saves.
|
||||
if (PropertyBlock.GetValue(__instance) == null)
|
||||
{
|
||||
PropertyBlock.SetValue(__instance, new MaterialPropertyBlock());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"name": "RacesOfValheim",
|
||||
"description": "A Valheim mod that adds ten custom playable races (Aswid, Draugh, Dvergar, Fenrir, Furling, Skadi, Skeleton, Sverm, Trenta, Trol) each with unique abilities, traits, race stations and a deep boss-driven progression system.",
|
||||
"version_number": "1.4.11",
|
||||
"version_number": "1.4.13",
|
||||
"website_url": "",
|
||||
"dependencies": [
|
||||
"denikson-BepInExPack_Valheim-5.4.2333",
|
||||
|
|
|
|||
|
|
@ -186,8 +186,10 @@ namespace RacesOfValheim
|
|||
/// is the build ghost, so `pos` is the authority on where this thing is actually going.
|
||||
/// Parameters are bound positionally (__0, __1) so a rename cannot break startup either.
|
||||
/// </summary>
|
||||
// Valheim 1.0 appended a 'bool cheated' parameter to this overload. The type array has to
|
||||
// match it exactly or the patch silently fails to bind and PatchAll throws.
|
||||
[HarmonyPatch(typeof(Player), "PlacePiece",
|
||||
new[] { typeof(Piece), typeof(Vector3), typeof(Quaternion), typeof(bool) })]
|
||||
new[] { typeof(Piece), typeof(Vector3), typeof(Quaternion), typeof(bool), typeof(bool) })]
|
||||
public static class PieceDensityLimitPatch
|
||||
{
|
||||
public static bool Prefix(Player __instance, Piece __0, Vector3 __1)
|
||||
|
|
|
|||
|
|
@ -163,6 +163,10 @@ namespace RacesOfValheim
|
|||
|
||||
public class RaceMenuWardBehavior : MonoBehaviour, Hoverable, Interactable
|
||||
{
|
||||
// New in Valheim 1.0: Hoverable gained this. Every vanilla implementation returns a
|
||||
// serialised m_hoverOffset, which is 0 unless the prefab sets one, so 0 is vanilla behaviour.
|
||||
public float GetHoverOffset() => 0f;
|
||||
|
||||
public string GetHoverName() => "Race Menu Ward";
|
||||
|
||||
public string GetHoverText()
|
||||
|
|
@ -286,9 +290,12 @@ namespace RacesOfValheim
|
|||
RacesOfValheim.ResetRace();
|
||||
});
|
||||
|
||||
// Refresh and not Close: unlike Reset Race, this one leaves the panel up so the two
|
||||
// World/Personal lines visibly change under the player. That is also how the old
|
||||
// no-op was noticed - the numbers stayed put while the message claimed a reset.
|
||||
AddButton("ResetProgressionBtn", "Reset Progression", new Vector2(170, -110), new Color(0.5f, 0.4f, 0.2f, 1f), () =>
|
||||
{
|
||||
RacesOfValheim.ResetProgression();
|
||||
RacesOfValheim.ResetProgression(out _);
|
||||
Refresh();
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ namespace RacesOfValheim
|
|||
{
|
||||
public const string PluginGUID = "com.nandor.racesofvalheim";
|
||||
public const string PluginName = "Races Of Valheim";
|
||||
public const string PluginVersion = "1.4.11";
|
||||
public const string PluginVersion = "1.4.13";
|
||||
|
||||
private readonly Harmony harmony = new Harmony(PluginGUID);
|
||||
|
||||
|
|
@ -160,18 +160,59 @@ namespace RacesOfValheim
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Clears the boss-progression override and falls back to the natural world state.
|
||||
/// Shared by the resetprogression console command and the Race Menu Ward.
|
||||
/// Gives back the progression a player claimed for themselves, and says plainly when there
|
||||
/// is none to give back. Shared by the resetprogression console command and the Race Menu
|
||||
/// Ward's Reset Progression button.
|
||||
///
|
||||
/// This used to clear BossProgressionManager.DebugState and nothing else - the console-only
|
||||
/// debug override, a static that is -1 at every launch and that the ward never writes. The
|
||||
/// two things the ward DOES write, RacesOfValheim_PersonalState and _PersonalMode in
|
||||
/// m_customData, were untouched, so for anyone who had not just typed increaseprogression
|
||||
/// in this session the button was a no-op by construction. It then reported
|
||||
/// GetCurrentProgressionState() as the result, which is the unchanged current tier - the
|
||||
/// "it always puts me back at the tier I'm on" the testers were describing. They were
|
||||
/// reading the one number that function could possibly have produced.
|
||||
///
|
||||
/// What it resets now is the personal tier only. The progression MODE is deliberately left
|
||||
/// alone: a player who chose to be independent of the server's kills stays independent,
|
||||
/// they just start claiming relics again from the bottom. And world progression is not this
|
||||
/// button's to reset - those are the world's global keys, shared by everyone on the server -
|
||||
/// so in world mode it says so rather than pretending.
|
||||
/// </summary>
|
||||
public static int ResetProgression()
|
||||
/// <param name="summary">Human-readable account of what actually changed, for the console.</param>
|
||||
public static int ResetProgression(out string summary)
|
||||
{
|
||||
// Still cleared, and first: it outranks both of the others in
|
||||
// GetCurrentProgressionState, so leaving it up would mask whatever we do below.
|
||||
bool hadDebugOverride = BossProgressionManager.DebugState != -1;
|
||||
BossProgressionManager.DebugState = -1;
|
||||
|
||||
bool clearedPersonal = false;
|
||||
if (BossProgressionManager.UsePersonalProgression && BossProgressionManager.HasPersonalState)
|
||||
{
|
||||
BossProgressionManager.ClearPersonalState();
|
||||
clearedPersonal = true;
|
||||
}
|
||||
|
||||
int state = BossProgressionManager.GetCurrentProgressionState();
|
||||
string boss = BossProgressionManager.GetBossNameForState(state);
|
||||
|
||||
if (clearedPersonal)
|
||||
summary = $"Personal progression reset to {boss} ({state}/{BossProgressionManager.MaxState}). Claim your relics again.";
|
||||
else if (BossProgressionManager.UsePersonalProgression)
|
||||
summary = $"Nothing to reset - you have claimed no relics yet ({state}/{BossProgressionManager.MaxState}).";
|
||||
else
|
||||
summary = $"Nothing to reset - you follow the world's progression: {boss} ({state}/{BossProgressionManager.MaxState}).";
|
||||
|
||||
if (hadDebugOverride) summary += " Debug override cleared.";
|
||||
|
||||
Player player = Player.m_localPlayer;
|
||||
if (player != null)
|
||||
{
|
||||
player.Message(MessageHud.MessageType.Center, $"Progression reset to: {state}");
|
||||
player.Message(MessageHud.MessageType.Center, summary);
|
||||
|
||||
// Progression drives stats and unlocks that are only recalculated when equipment is
|
||||
// set up, so nudge that or the new tier will not show until something else does.
|
||||
Traverse.Create(player).Method("SetupEquipment").GetValue();
|
||||
}
|
||||
|
||||
|
|
@ -1299,8 +1340,8 @@ namespace RacesOfValheim
|
|||
|
||||
public override void Run(string[] args)
|
||||
{
|
||||
int state = RacesOfValheim.ResetProgression();
|
||||
Console.instance.Print($"[DEBUG] Progression state reset to natural world state: {state}");
|
||||
RacesOfValheim.ResetProgression(out string summary);
|
||||
Console.instance.Print($"[DEBUG] {summary}");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -282,7 +282,9 @@ namespace RacesOfValheim
|
|||
HitData hitData = new HitData();
|
||||
hitData.m_damage = staffDrop.m_itemData.m_shared.m_damages;
|
||||
hitData.SetAttacker(Player.m_localPlayer);
|
||||
|
||||
// The Drake breath is a fixed three-shard volley, so one third each.
|
||||
SkadiMagicSkill.TagCast(hitData, 3);
|
||||
|
||||
proj.Setup(Player.m_localPlayer, targetDir * vel, -1f, hitData, staffDrop.m_itemData, null);
|
||||
}
|
||||
|
||||
|
|
@ -376,6 +378,7 @@ namespace RacesOfValheim
|
|||
HitData hitData = new HitData();
|
||||
hitData.m_damage = staffDrop.m_itemData.m_shared.m_damages;
|
||||
hitData.SetAttacker(Player.m_localPlayer);
|
||||
SkadiMagicSkill.TagCast(hitData, projCount);
|
||||
proj.Setup(Player.m_localPlayer, targetDir * vel, -1f, hitData, staffDrop.m_itemData, null);
|
||||
}
|
||||
|
||||
|
|
@ -484,6 +487,7 @@ namespace RacesOfValheim
|
|||
hitData.m_damage.m_frost += hitData.m_damage.m_fire;
|
||||
hitData.m_damage.m_fire = 0f;
|
||||
hitData.SetAttacker(Player.m_localPlayer);
|
||||
SkadiMagicSkill.TagCast(hitData, projCount);
|
||||
|
||||
if (proj != null)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -45,6 +45,12 @@ namespace RacesOfValheim
|
|||
public static ConfigEntry<float> AuraDamagePerTick;
|
||||
public static ConfigEntry<float> AuraTickInterval;
|
||||
|
||||
// ─── Elemental Magic experience ─────────────────────────────────────────
|
||||
// See SkadiMagicSkill for why a cast's budget is split across its projectiles and why the
|
||||
// aura's share is a fraction of a cast's.
|
||||
public static ConfigEntry<float> MagicSkillGainPerCast;
|
||||
public static ConfigEntry<float> AuraSkillGainPerTick;
|
||||
|
||||
// ─── Passive combat ──────────────────────────────────────────────────
|
||||
public static ConfigEntry<float> BonusFrostDamagePerState;
|
||||
|
||||
|
|
@ -126,6 +132,12 @@ namespace RacesOfValheim
|
|||
AuraTickInterval = config.Bind(aura, "Tick Interval", 1f,
|
||||
new ConfigDescription("Seconds between aura damage ticks.", new AcceptableValueRange<float>(0.1f, 5f)));
|
||||
|
||||
const string magicSkill = "Skadi - Elemental Magic Skill";
|
||||
MagicSkillGainPerCast = config.Bind(magicSkill, "Gain Per Cast", 1f,
|
||||
new ConfigDescription("Elemental Magic experience for one cast that connects - the Cold Spell and all three dragon breaths. Split across the projectiles a cast throws, so a ten-shard burst is worth the same as one shard. Nothing is earned by a shot that hits no one. 0 turns spell experience off.", new AcceptableValueRange<float>(0f, 5f)));
|
||||
AuraSkillGainPerTick = config.Bind(magicSkill, "Aura Gain Per Tick", 0.1f,
|
||||
new ConfigDescription("Elemental Magic experience for one Frost Aura tick that burned at least one enemy - once per tick, not once per enemy. Deliberately a fraction of a cast: the aura ticks every second on its own. 0 turns aura experience off.", new AcceptableValueRange<float>(0f, 1f)));
|
||||
|
||||
const string scale = "Skadi - Dragon Form Scale";
|
||||
DrakeScale = config.Bind(scale, "Drake Scale", 0.9f,
|
||||
new ConfigDescription("Model scale while transformed into the Drake (tier 3-4).", new AcceptableValueRange<float>(0.1f, 2f)));
|
||||
|
|
|
|||
83
JotunnModStub/Skadi/SkadiMagicSkill.cs
Normal file
83
JotunnModStub/Skadi/SkadiMagicSkill.cs
Normal file
|
|
@ -0,0 +1,83 @@
|
|||
namespace RacesOfValheim
|
||||
{
|
||||
/// <summary>
|
||||
/// Elemental Magic experience for Skadi's spellcasting, in one place because four call sites
|
||||
/// need the same two lines and the same piece of arithmetic.
|
||||
///
|
||||
/// WHY NOTHING WAS LEVELLING BEFORE. Every one of Skadi's casts builds its HitData by hand and
|
||||
/// never touched HitData.m_skill, which leaves it at SkillType.None. Vanilla's Skills.RaiseSkill
|
||||
/// returns on its first instruction when the type is None, so the experience was not merely
|
||||
/// small - it was structurally impossible. Read out of assembly_valheim, along with the path
|
||||
/// that makes the fix a one-liner:
|
||||
///
|
||||
/// Projectile.Setup copies hitData.m_skill into Projectile.m_skill, and
|
||||
/// hitData.m_skillRaiseAmount into Projectile.m_raiseSkillAmount.
|
||||
/// Projectile.OnHit calls owner.RaiseSkill(m_skill, m_raiseSkillAmount) - once, and only
|
||||
/// on the branch where the projectile actually damaged something.
|
||||
///
|
||||
/// So a tagged HitData gets vanilla's own behaviour for free: experience on a hit that lands,
|
||||
/// nothing for a shot into a hillside, and no double-counting. That is better than raising the
|
||||
/// skill at cast time, which would pay a player for missing.
|
||||
///
|
||||
/// WHY THE AMOUNT IS DIVIDED. A cast is one spell however many things leave the hand. The
|
||||
/// improved Cold Spell throws ten shards and the dragon breaths throw up to a volley each, and
|
||||
/// every one of those is its own Projectile with its own OnHit - so an untouched
|
||||
/// m_skillRaiseAmount of 1 would pay ten times for one cast. The budget is split the same way
|
||||
/// ColdSpellKickCoroutine already splits its damage budget across shards, for the same reason.
|
||||
///
|
||||
/// WHAT IS DELIBERATELY NOT HERE. The dragon forms' melee (DrakeFormBehavior.ExecuteMeleeDamage)
|
||||
/// stays on Unarmed: it already tags itself that way and already scales off the Unarmed skill
|
||||
/// level - it is a maul, not a spell. And the Crystal Golem is a hammer piece, not a cast, so it
|
||||
/// pays Building experience through vanilla's own placement path.
|
||||
/// </summary>
|
||||
public static class SkadiMagicSkill
|
||||
{
|
||||
/// <summary>
|
||||
/// Marks a cast's HitData as Elemental Magic and gives it its share of the cast's
|
||||
/// experience. Call it before Projectile.Setup - Setup is what copies both fields onto the
|
||||
/// projectile, so anything written afterwards is never read.
|
||||
/// </summary>
|
||||
/// <param name="hit">The HitData about to be handed to Projectile.Setup.</param>
|
||||
/// <param name="projectilesInCast">
|
||||
/// How many projectiles this one cast throws. The cast's whole experience budget is divided
|
||||
/// by it, so a ten-shard burst and a single shard are worth the same.
|
||||
/// </param>
|
||||
public static void TagCast(HitData hit, int projectilesInCast)
|
||||
{
|
||||
if (hit == null) return;
|
||||
|
||||
float perCast = SkadiConfig.MagicSkillGainPerCast != null
|
||||
? SkadiConfig.MagicSkillGainPerCast.Value
|
||||
: 1f;
|
||||
|
||||
// Zero is the off switch, and it has to leave m_skill alone as well as the amount:
|
||||
// Skills.RaiseSkill would still be entered with a real type and a zero factor, and
|
||||
// Skill.Raise does its own bookkeeping before it looks at the number.
|
||||
if (perCast <= 0f) return;
|
||||
|
||||
if (projectilesInCast < 1) projectilesInCast = 1;
|
||||
|
||||
hit.m_skill = Skills.SkillType.ElementalMagic;
|
||||
hit.m_skillRaiseAmount = perCast / projectilesInCast;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The Frost Aura's share. Unlike a cast the aura has no projectile to hang experience on,
|
||||
/// so it is raised directly - once per tick that actually burned something, never once per
|
||||
/// enemy. A three metre aura ticking every second through a pack would otherwise pay out
|
||||
/// several times a second and take the skill to cap on a single fight, which is why the
|
||||
/// default is a fraction rather than the 1 a cast is worth.
|
||||
/// </summary>
|
||||
public static void RaiseForAuraTick()
|
||||
{
|
||||
if (Player.m_localPlayer == null) return;
|
||||
|
||||
float gain = SkadiConfig.AuraSkillGainPerTick != null
|
||||
? SkadiConfig.AuraSkillGainPerTick.Value
|
||||
: 0f;
|
||||
if (gain <= 0f) return;
|
||||
|
||||
Player.m_localPlayer.RaiseSkill(Skills.SkillType.ElementalMagic, gain);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -118,7 +118,9 @@ namespace RacesOfValheim
|
|||
}
|
||||
}
|
||||
|
||||
[HarmonyPatch(typeof(SEMan), "AddStatusEffect", new System.Type[] { typeof(int), typeof(bool), typeof(int), typeof(float) })]
|
||||
// Valheim 1.0 appended a 'short variant' parameter to this overload. The type array has to
|
||||
// match it exactly or the patch silently fails to bind and PatchAll throws.
|
||||
[HarmonyPatch(typeof(SEMan), "AddStatusEffect", new System.Type[] { typeof(int), typeof(bool), typeof(int), typeof(float), typeof(short) })]
|
||||
public static class SkadiSEManPatch
|
||||
{
|
||||
public static bool Prefix(SEMan __instance, ref int nameHash)
|
||||
|
|
|
|||
|
|
@ -431,6 +431,9 @@ namespace RacesOfValheim
|
|||
HitData hitData = new HitData();
|
||||
hitData.m_damage.m_frost = shardDamage;
|
||||
hitData.SetAttacker(Player.m_localPlayer);
|
||||
// Before Setup, which is what copies the skill and its amount onto the
|
||||
// projectile. Same split as the damage budget above, and for the same reason.
|
||||
SkadiMagicSkill.TagCast(hitData, count);
|
||||
proj.Setup(Player.m_localPlayer, lookDir * staffDrop.m_itemData.m_shared.m_attack.m_projectileVel, -1f, hitData, staffDrop.m_itemData, null);
|
||||
}
|
||||
|
||||
|
|
@ -509,11 +512,15 @@ namespace RacesOfValheim
|
|||
{
|
||||
if (Player.m_localPlayer == null) return;
|
||||
Vector3 center = Player.m_localPlayer.transform.position;
|
||||
|
||||
// Once per tick, not once per enemy - see SkadiMagicSkill.RaiseForAuraTick.
|
||||
bool burnedSomething = false;
|
||||
|
||||
foreach (Character c in Character.GetAllCharacters())
|
||||
{
|
||||
if (c == Player.m_localPlayer) continue;
|
||||
if (c.IsTamed() || c.IsPlayer()) continue;
|
||||
|
||||
|
||||
if (Vector3.Distance(center, c.transform.position) <= SkadiConfig.AuraRadius.Value)
|
||||
{
|
||||
HitData hit = new HitData();
|
||||
|
|
@ -522,8 +529,11 @@ namespace RacesOfValheim
|
|||
hit.m_dir = (c.transform.position - center).normalized;
|
||||
hit.SetAttacker(Player.m_localPlayer);
|
||||
c.ApplyDamage(hit, true, false);
|
||||
burnedSomething = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (burnedSomething) SkadiMagicSkill.RaiseForAuraTick();
|
||||
}
|
||||
|
||||
private void TryTransformWithRules(SkadiProgression.FormRules rules)
|
||||
|
|
|
|||
|
|
@ -308,8 +308,9 @@ namespace RacesOfValheim
|
|||
VisEquipment vis = Player.m_localPlayer.GetComponent<VisEquipment>();
|
||||
if (vis != null)
|
||||
{
|
||||
vis.SetHairItem("");
|
||||
vis.SetBeardItem("");
|
||||
// Since Valheim 1.0 these take an item hash, not a prefab name. 0 is the empty slot.
|
||||
vis.SetHairItem(0);
|
||||
vis.SetBeardItem(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -467,6 +467,10 @@ namespace RacesOfValheim
|
|||
"[<color=yellow><b>$KEY_Use</b></color>] Feed it a stack";
|
||||
}
|
||||
|
||||
// New in Valheim 1.0: Hoverable gained this. Every vanilla implementation returns a
|
||||
// serialised m_hoverOffset, which is 0 unless the prefab sets one, so 0 is vanilla behaviour.
|
||||
public float GetHoverOffset() => 0f;
|
||||
|
||||
public string GetHoverName() => SvermHiveStage.NameOf(SvermHiveStage.Of(transform));
|
||||
|
||||
private ZNetView nview;
|
||||
|
|
|
|||
|
|
@ -211,6 +211,10 @@ namespace RacesOfValheim
|
|||
|
||||
public bool UseItem(Humanoid user, ItemDrop.ItemData item) => false;
|
||||
|
||||
// New in Valheim 1.0: Hoverable gained this. Every vanilla implementation returns a
|
||||
// serialised m_hoverOffset, which is 0 unless the prefab sets one, so 0 is vanilla behaviour.
|
||||
public float GetHoverOffset() => 0f;
|
||||
|
||||
public string GetHoverName() => Title;
|
||||
|
||||
public string GetHoverText()
|
||||
|
|
@ -444,6 +448,10 @@ namespace RacesOfValheim
|
|||
|
||||
public bool UseItem(Humanoid user, ItemDrop.ItemData item) => false;
|
||||
|
||||
// New in Valheim 1.0: Hoverable gained this. Every vanilla implementation returns a
|
||||
// serialised m_hoverOffset, which is 0 unless the prefab sets one, so 0 is vanilla behaviour.
|
||||
public float GetHoverOffset() => 0f;
|
||||
|
||||
public string GetHoverName() => SvermHiveMarketPiece.DisplayName;
|
||||
|
||||
public string GetHoverText()
|
||||
|
|
|
|||
|
|
@ -682,9 +682,10 @@ namespace RacesOfValheim
|
|||
|
||||
if (player.GetComponent<CarapaceMark>() == null) player.gameObject.AddComponent<CarapaceMark>();
|
||||
|
||||
visEq.SetChestItem(SvermConfig.CarapaceChestVisual);
|
||||
visEq.SetLegItem(SvermConfig.CarapaceLegsVisual);
|
||||
visEq.SetHelmetItem(SvermConfig.CarapaceHelmetVisual);
|
||||
// Since Valheim 1.0 these three take an item hash rather than a prefab name.
|
||||
visEq.SetChestItem(VisualHash(SvermConfig.CarapaceChestVisual));
|
||||
visEq.SetLegItem(VisualHash(SvermConfig.CarapaceLegsVisual));
|
||||
visEq.SetHelmetItem(VisualHash(SvermConfig.CarapaceHelmetVisual));
|
||||
|
||||
int state = GetRenderState(player);
|
||||
|
||||
|
|
@ -697,7 +698,7 @@ namespace RacesOfValheim
|
|||
/// Puts the three slots back to whatever the player actually has equipped.
|
||||
///
|
||||
/// The same three lines vanilla's own Humanoid.SetupVisEquipment writes - the item's drop
|
||||
/// prefab name, or "" for an empty slot - rather than calling that method, because it also
|
||||
/// prefab name hashed, or 0 when empty - rather than calling that method, because it also
|
||||
/// rewrites the hands, the shoulders and the utility slot, and the Sverm never touched
|
||||
/// those. Restoring only what was overridden cannot disturb another race's visuals or a
|
||||
/// weapon that some other patch is mid-way through swapping.
|
||||
|
|
@ -707,17 +708,25 @@ namespace RacesOfValheim
|
|||
/// </summary>
|
||||
private static void RestoreEquipmentVisuals(Player player, VisEquipment visEq)
|
||||
{
|
||||
visEq.SetChestItem(EquippedVisualName(player, "m_chestItem"));
|
||||
visEq.SetLegItem(EquippedVisualName(player, "m_legItem"));
|
||||
visEq.SetHelmetItem(EquippedVisualName(player, "m_helmetItem"));
|
||||
visEq.SetChestItem(EquippedVisualHash(player, "m_chestItem"));
|
||||
visEq.SetLegItem(EquippedVisualHash(player, "m_legItem"));
|
||||
visEq.SetHelmetItem(EquippedVisualHash(player, "m_helmetItem"));
|
||||
}
|
||||
|
||||
/// <summary>The prefab name VisEquipment wants for an equipped slot, or "" when it is empty.</summary>
|
||||
private static string EquippedVisualName(Player player, string field)
|
||||
/// <summary>
|
||||
/// What VisEquipment has wanted since Valheim 1.0: an item hash instead of a prefab name.
|
||||
/// 0 is the empty slot - the same value vanilla Humanoid.SetupVisEquipment passes for a
|
||||
/// slot holding nothing.
|
||||
/// </summary>
|
||||
private static int VisualHash(string prefabName) =>
|
||||
string.IsNullOrEmpty(prefabName) ? 0 : prefabName.GetStableHashCode();
|
||||
|
||||
/// <summary>The item hash VisEquipment wants for an equipped slot, or 0 when it is empty.</summary>
|
||||
private static int EquippedVisualHash(Player player, string field)
|
||||
{
|
||||
ItemDrop.ItemData item = Traverse.Create((Humanoid)player).Field<ItemDrop.ItemData>(field).Value;
|
||||
if (item == null || item.m_dropPrefab == null) return "";
|
||||
return item.m_dropPrefab.name;
|
||||
if (item == null || item.m_dropPrefab == null) return 0;
|
||||
return VisualHash(item.m_dropPrefab.name);
|
||||
}
|
||||
|
||||
private static void TintInstances(object value, int state)
|
||||
|
|
|
|||
|
|
@ -279,8 +279,10 @@ namespace RacesOfValheim
|
|||
/// Race lock plus the boss gate, in one prefix - same shape as TrolTotemRaceLockPatch, with a
|
||||
/// second refusal added for the progression check the Root also needs.
|
||||
/// </summary>
|
||||
// Valheim 1.0 appended a 'bool cheated' parameter to this overload. The type array has to
|
||||
// match it exactly or the patch silently fails to bind and PatchAll throws.
|
||||
[HarmonyPatch(typeof(Player), "PlacePiece",
|
||||
new[] { typeof(Piece), typeof(Vector3), typeof(Quaternion), typeof(bool) })]
|
||||
new[] { typeof(Piece), typeof(Vector3), typeof(Quaternion), typeof(bool), typeof(bool) })]
|
||||
public static class TrentaElderRootPlacementPatch
|
||||
{
|
||||
public static bool Prefix(Player __instance, Piece __0)
|
||||
|
|
|
|||
|
|
@ -134,7 +134,9 @@ namespace RacesOfValheim
|
|||
/// ever adds Wet, always through this exact four-argument SEMan.AddStatusEffect overload,
|
||||
/// so patching that call is equivalent to patching every path Wet could arrive by.
|
||||
/// </summary>
|
||||
[HarmonyPatch(typeof(SEMan), "AddStatusEffect", new System.Type[] { typeof(int), typeof(bool), typeof(int), typeof(float) })]
|
||||
// Valheim 1.0 appended a 'short variant' parameter to this overload. The type array has to
|
||||
// match it exactly or the patch silently fails to bind and PatchAll throws.
|
||||
[HarmonyPatch(typeof(SEMan), "AddStatusEffect", new System.Type[] { typeof(int), typeof(bool), typeof(int), typeof(float), typeof(short) })]
|
||||
public static class Trenta_SEMan_AddStatusEffect_WetImmunity_Patch
|
||||
{
|
||||
public static bool Prefix(SEMan __instance, int nameHash)
|
||||
|
|
|
|||
|
|
@ -362,8 +362,10 @@ namespace RacesOfValheim
|
|||
/// The race lock. Every other station in this mod is buildable by anyone; this one is not, so the
|
||||
/// refusal is caught at placement - before the core wood and the head are spent.
|
||||
/// </summary>
|
||||
// Valheim 1.0 appended a 'bool cheated' parameter to this overload. The type array has to
|
||||
// match it exactly or the patch silently fails to bind and PatchAll throws.
|
||||
[HarmonyPatch(typeof(Player), "PlacePiece",
|
||||
new[] { typeof(Piece), typeof(Vector3), typeof(Quaternion), typeof(bool) })]
|
||||
new[] { typeof(Piece), typeof(Vector3), typeof(Quaternion), typeof(bool), typeof(bool) })]
|
||||
public static class TrolTotemRaceLockPatch
|
||||
{
|
||||
public static bool Prefix(Player __instance, Piece __0)
|
||||
|
|
|
|||
|
|
@ -122,8 +122,9 @@ namespace RacesOfValheim
|
|||
VisEquipment vis = m_player.GetComponent<VisEquipment>();
|
||||
if (vis != null)
|
||||
{
|
||||
vis.SetHairItem("");
|
||||
vis.SetBeardItem("");
|
||||
// Since Valheim 1.0 these take an item hash, not a prefab name. 0 is the empty slot.
|
||||
vis.SetHairItem(0);
|
||||
vis.SetBeardItem(0);
|
||||
|
||||
// Hide Helmet
|
||||
var helmetObj = HarmonyLib.Traverse.Create(vis).Field<GameObject>("m_helmetItemInstance").Value;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue