warvulture
This commit is contained in:
parent
4559e0b9e1
commit
e9d6e78ec8
15 changed files with 1041 additions and 489 deletions
|
|
@ -24,8 +24,8 @@ namespace RacesOfValheim
|
|||
public const string RaceId = "Sverm";
|
||||
|
||||
public const string StatsSE = "SE_SvermStats";
|
||||
public const string StingerSE = "SE_SvermStingerForm";
|
||||
public const string StingerCdSE = "SE_SvermStingerCooldown";
|
||||
public const string RavagerSE = "SE_SvermRavagerForm";
|
||||
public const string RavagerCdSE = "SE_SvermRavagerCooldown";
|
||||
|
||||
// Mirrors the ZDO key layout the other races use, so remote clients can work out the tier
|
||||
// without having the local player's progression state.
|
||||
|
|
@ -144,7 +144,7 @@ namespace RacesOfValheim
|
|||
public const int VenomGlandsState = 4;
|
||||
public const int AcidHemolymphState = 4;
|
||||
public const int VestigialWingsState = 5;
|
||||
public const int StingerMorphState = 6;
|
||||
public const int RavagerFormState = 6;
|
||||
public const int EitrSacsState = 6;
|
||||
public const int MajesticCarapaceState = 7;
|
||||
public const int SurrenalGlandsState = 7;
|
||||
|
|
@ -231,38 +231,60 @@ namespace RacesOfValheim
|
|||
// ─── Carapace Regeneration (state 8) ─────────────────────────────────
|
||||
public static readonly float CarapaceRegenPerSecond = 0.5f;
|
||||
|
||||
// ─── Stinger Morph (state 6) ─────────────────────────────────────────
|
||||
public const string StingerCreature = "Deathsquito";
|
||||
public static readonly float StingerDurationSeconds = 120f;
|
||||
public static readonly float StingerCooldownSeconds = 480f;
|
||||
// ─── Ravager Strain (state 6) ────────────────────────────────────────
|
||||
// Replaces the old Stinger Morph (a Deathsquito flight form). Players found that form's
|
||||
// glass-cannon trade too strong for what it cost; this is the opposite shape - no flight,
|
||||
// no summons, and the fragility multiplier is gone, replaced by a straight armour buff.
|
||||
// Same duration and cooldown as the form it replaces.
|
||||
public const string RavagerCreature = "SeekerBrute";
|
||||
public static readonly float RavagerDurationSeconds = 120f; // 2 minutes
|
||||
public static readonly float RavagerCooldownSeconds = 300f; // 5 minutes
|
||||
|
||||
// The Brute's four real attack items, named and verified with `dumpelder SeekerBrute` in
|
||||
// a live world - not guessed. Their numbers are read once by SvermRavagerAttacks and
|
||||
// applied by hand in RavagerFormBehavior's own attack coroutines (Physics.OverlapSphere,
|
||||
// the same method Fenrir and Skadi's forms already use); nothing here is cloned or
|
||||
// equipped any more.
|
||||
public const string RavagerBiteWeapon = "SeekerBrute_bite"; // slash 100, left click
|
||||
public const string RavagerRamWeapon = "SeekerBrute_ram"; // blunt/chop/pickaxe 100, right click / G
|
||||
public const string RavagerSlamWeapon = "SeekerBrute_groundslam"; // AoE stomp, blunt/chop/pickaxe 120-100-100, middle click
|
||||
|
||||
/// <summary>
|
||||
/// Multiplier on every point of damage taken while in form. 2.5 means a blow that the
|
||||
/// carapace would shrug off very nearly ends you.
|
||||
///
|
||||
/// This is the entire cost of the ability and it has to be steep: in form you deal the
|
||||
/// hardest single hit in the Plains and you can leave any fight by going straight up. The
|
||||
/// balance is not the cooldown, it is that a single arrow answers you.
|
||||
/// The Brute's roar. type=None on the real creature - it lands no hit there - but the
|
||||
/// item still carries real numbers (slash 80, chop 10) nobody ever wired to a hitbox.
|
||||
/// Players asked for a use for it: a short-cooldown AoE around the player rather than a
|
||||
/// forward swing, bound to G once G stopped being needed for anything else.
|
||||
/// </summary>
|
||||
public static readonly float StingerFragility = 2.5f;
|
||||
public const string RavagerTauntWeapon = "SeekerBrute_Taunt";
|
||||
|
||||
// ─── The escort ──────────────────────────────────────────────────────
|
||||
/// <summary>
|
||||
/// Two deathsquitoes called up with the form, and they OUTLIVE it on purpose.
|
||||
///
|
||||
/// Three minutes against the form's two. The extra minute is the whole idea: the form ends
|
||||
/// wherever it ends, usually in the air, and the Sverm comes back to being a slow armoured
|
||||
/// thing halfway through a fall. The escort is what covers that minute. Then it dies too.
|
||||
/// What the carapace's own armour value (SvermCarapace.GetArmor) is multiplied by while
|
||||
/// the form is up. 2 means the tank doubles its damage reduction for the same two minutes
|
||||
/// the old form spent being nearly one-shot by anything.
|
||||
/// </summary>
|
||||
public const int EscortCount = 2;
|
||||
public static readonly float EscortLifetimeSeconds = 180f;
|
||||
public static readonly float EscortSpawnSpread = 2.5f;
|
||||
public static readonly float RavagerArmorMultiplier = 2f;
|
||||
|
||||
// ─── The taunt (G) ───────────────────────────────────────────────────
|
||||
/// <summary>Its own cooldown, short and separate from the main three attacks' own lock timing.</summary>
|
||||
public static readonly float RavagerTauntCooldownSeconds = 10f;
|
||||
|
||||
/// <summary>Centred on the player, not projected forward like a swing - a roar goes out, not in.</summary>
|
||||
public static readonly float RavagerTauntRadius = 3f;
|
||||
|
||||
// Candidates tried in order, same PlayEffect pattern MorphIn/MorphOutEffects already use:
|
||||
// a wrong guess is silently skipped rather than an error. Not confirmed to exist - the
|
||||
// Brute's own Attack effect slots were all empty when dumped, so if a roar sound exists
|
||||
// at all it lives somewhere this file has not found yet.
|
||||
public static readonly string[] RavagerTauntSoundEffects = { "sfx_seeker_brute_taunt", "sfx_seekerbrute_taunt", "sfx_seeker_taunt" };
|
||||
|
||||
// ─── Transformation effects ──────────────────────────────────────────
|
||||
// The Seeker's own spawn and death bursts, verified in the manifest. vfx_boar_death is the
|
||||
// fallback because it is what the Aswid uses and is certain to exist.
|
||||
public static readonly string[] MorphInEffects = { "fx_seeker_spawn", "vfx_boar_death" };
|
||||
public static readonly string[] MorphOutEffects = { "fx_seeker_death", "vfx_boar_death" };
|
||||
// The Seeker's own spawn and death bursts are the verified fallback - carried over from
|
||||
// the old Stinger Morph, which used them successfully. A Brute-specific pair is tried
|
||||
// first on the chance this build has one; PlayEffect already skips silently past any name
|
||||
// that does not resolve, so a wrong guess here costs nothing. vfx_boar_death is the last
|
||||
// resort because it is what the Aswid uses and is certain to exist.
|
||||
public static readonly string[] RavagerMorphInEffects = { "fx_seeker_brute_spawn", "fx_seeker_spawn", "vfx_boar_death" };
|
||||
public static readonly string[] RavagerMorphOutEffects = { "fx_seeker_brute_death", "fx_seeker_death", "vfx_boar_death" };
|
||||
|
||||
// ─── Palette ─────────────────────────────────────────────────────────
|
||||
// Read off a Seeker Soldier. The exposed skin is almost black and matte: what makes the
|
||||
|
|
|
|||
|
|
@ -37,11 +37,12 @@ namespace RacesOfValheim
|
|||
public static ConfigEntry<float> EmberGlowStrength;
|
||||
|
||||
// ─── Keybinds ────────────────────────────────────────────────────────
|
||||
public static ConfigEntry<KeyboardShortcut> StingerKey;
|
||||
public static ConfigEntry<KeyboardShortcut> RavagerKey;
|
||||
|
||||
// ─── Stinger Morph, the model ────────────────────────────────────────
|
||||
public static ConfigEntry<float> StingerScaleMultiplier;
|
||||
public static ConfigEntry<float> StingerYawDegrees;
|
||||
// ─── Ravager Strain, the model ───────────────────────────────────────
|
||||
public static ConfigEntry<float> RavagerScaleMultiplier;
|
||||
public static ConfigEntry<float> RavagerYawDegrees;
|
||||
public static ConfigEntry<float> RavagerAttackOffsetValue;
|
||||
|
||||
// ─── Colony caps ─────────────────────────────────────────────────────
|
||||
// Every ceiling on how many things the colony can have alive at once, in one section, so
|
||||
|
|
@ -82,14 +83,15 @@ namespace RacesOfValheim
|
|||
|
||||
// G, like every other first transformation in the mod - the Aswid's bat, the Fenrir's
|
||||
// wolf, the Dvergar's ping. A character only ever has one race, so they never collide.
|
||||
StingerKey = config.Bind(keybinds, "Stinger Morph", new KeyboardShortcut(UnityEngine.KeyCode.G),
|
||||
"Turns into a Deathsquito, and back. Unlocked at Yagluth.");
|
||||
RavagerKey = config.Bind(keybinds, "Ravager Strain", new KeyboardShortcut(UnityEngine.KeyCode.G),
|
||||
"Turns into a Seeker Brute, and back. Unlocked at Yagluth.");
|
||||
|
||||
const string stinger = "Sverm - Stinger Morph";
|
||||
const string ravager = "Sverm - Ravager Strain";
|
||||
|
||||
StingerScaleMultiplier = config.Bind(stinger, "Scale", 1f,
|
||||
"Multiplies the deathsquito model's OWN authored scale. 1 means 'the size the " +
|
||||
"game draws one'. Raise it if the insect reads as too small to be you.");
|
||||
RavagerScaleMultiplier = config.Bind(ravager, "Scale", 1f,
|
||||
"Multiplies the Seeker Brute model's OWN authored scale. 1 means 'the full size " +
|
||||
"the game draws one, bulk and all' - the form is meant to be worn at the " +
|
||||
"creature's own size, not shrunk to fit.");
|
||||
|
||||
const string nest = "Sverm - Nest";
|
||||
|
||||
|
|
@ -180,10 +182,24 @@ namespace RacesOfValheim
|
|||
"infected and producing a worker, so this is the number that really decides how " +
|
||||
"busy a base gets.");
|
||||
|
||||
StingerYawDegrees = config.Bind(stinger, "Yaw", 180f,
|
||||
"Turns the model on the vertical axis, in degrees. The creature's forward is not " +
|
||||
"the player's, so without this it flies looking back at you. 180 is the usual " +
|
||||
"answer; try 90 or -90 if it comes out sideways.");
|
||||
// FOUND IN PLAY: 180, the figure that fixed the flying Deathsquito, faces the Seeker
|
||||
// Brute straight at the camera - its own forward already matches the player's, unlike
|
||||
// the Deathsquito's. Different source rig, different answer; 0 is correct here.
|
||||
RavagerYawDegrees = config.Bind(ravager, "Yaw", 0f,
|
||||
"Turns the model on the vertical axis, in degrees. 0 is correct for the Seeker " +
|
||||
"Brute; try 180 (or 90 / -90) if a future model swap ends up facing the wrong way.");
|
||||
|
||||
// FOUND IN PLAY: the hit itself lands where the PLAYER'S own body is, at the Brute's
|
||||
// native scale (RavagerScale) the visible mouth/claws sit well forward of that - so
|
||||
// the swing visibly connects a metre or more short of where the model appears to
|
||||
// bite. Attack.m_attackOffset pushes the hit-detection origin forward from the
|
||||
// player before m_attackRange is measured out from it; 1.5 is a first guess sized
|
||||
// against the model's own scale, not a verified figure, so it lives here to be
|
||||
// walked in by eye rather than baked into SvermConfig as if it were.
|
||||
RavagerAttackOffsetValue = config.Bind(ravager, "Attack Reach Offset", 1.5f,
|
||||
"How far forward of the player, in metres, the Brute's attacks are measured from. " +
|
||||
"Raise it if a swing visibly connects short of the model's mouth/claws; lower it " +
|
||||
"if it connects well past them.");
|
||||
|
||||
EmberGlowStrength = config.Bind(ember, "Glow Strength", SvermConfig.EmberGlowStrength,
|
||||
"How hot the chitin burns at Fader. This multiplies an HDR colour and it is applied " +
|
||||
|
|
@ -246,8 +262,9 @@ namespace RacesOfValheim
|
|||
public static float NestVfxScale => NestVfxScaleValue?.Value ?? SvermConfig.NestVfxScale;
|
||||
public static float BeehiveVfxScale => BeehiveVfxScaleValue?.Value ?? SvermConfig.BeehiveVfxScale;
|
||||
|
||||
public static float StingerScale => StingerScaleMultiplier?.Value ?? 1f;
|
||||
public static float StingerYaw => StingerYawDegrees?.Value ?? 180f;
|
||||
public static float RavagerScale => RavagerScaleMultiplier?.Value ?? 1f;
|
||||
public static float RavagerYaw => RavagerYawDegrees?.Value ?? 0f;
|
||||
public static float RavagerAttackOffset => RavagerAttackOffsetValue?.Value ?? 1.5f;
|
||||
|
||||
public static float SizeSmall => SpineSizeSmall?.Value ?? SvermConfig.SpineSizeSmall;
|
||||
public static float SizeFull => SpineSizeFull?.Value ?? SvermConfig.SpineSizeFull;
|
||||
|
|
|
|||
|
|
@ -37,7 +37,19 @@ namespace RacesOfValheim
|
|||
public static void Postfix(Player __instance, ref float __result)
|
||||
{
|
||||
if (__instance == null || !SvermVisuals.IsSvermPlayer(__instance)) return;
|
||||
__result += SvermCarapace.GetArmor(SvermVisuals.GetRenderState(__instance));
|
||||
|
||||
float carapace = SvermCarapace.GetArmor(SvermVisuals.GetRenderState(__instance));
|
||||
|
||||
// Ravager Strain's whole benefit: the carapace is worth double for as long as the
|
||||
// form holds. Multiplying only the carapace's own contribution, not the total,
|
||||
// keeps a cape or trinket's armour honest instead of doubling gear the form had
|
||||
// nothing to do with.
|
||||
if (SvermRavagerForm.IsActive)
|
||||
{
|
||||
carapace *= SvermConfig.RavagerArmorMultiplier;
|
||||
}
|
||||
|
||||
__result += carapace;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -106,26 +118,13 @@ namespace RacesOfValheim
|
|||
int state = SvermVisuals.GetRenderState(attackingPlayer);
|
||||
SvermProgression.SvermRules rules = SvermProgression.GetRules(state);
|
||||
|
||||
// Unarmed only - the claws' own tier-scaled blow. Ravager Strain's own hits
|
||||
// (RavagerFormBehavior.ExecuteDamage) are built with Skills.SkillType.Swords
|
||||
// on purpose, specifically so they never reach this branch and get overwritten
|
||||
// by the claws' numbers - the Brute's own damage is meant to stand as-is.
|
||||
if (hit.m_skill == Skills.SkillType.Unarmed)
|
||||
{
|
||||
// In Stinger Morph the hands are gone and what lands is a needle. The
|
||||
// deathsquito's own figure is read off the creature, so it stays whatever
|
||||
// vanilla says a deathsquito is worth; if it could not be read it comes
|
||||
// back as zeroes and the claws answer instead.
|
||||
HitData.DamageTypes sting = SvermStingerForm.IsActive
|
||||
? SvermStingerForm.GetStingDamage()
|
||||
: default(HitData.DamageTypes);
|
||||
|
||||
if (sting.m_pierce + sting.m_slash + sting.m_blunt > 0f)
|
||||
{
|
||||
hit.m_damage.m_pierce = sting.m_pierce;
|
||||
hit.m_damage.m_slash = sting.m_slash;
|
||||
hit.m_damage.m_blunt = sting.m_blunt;
|
||||
}
|
||||
else
|
||||
{
|
||||
SvermClaws.ApplyToUnarmedHit(hit, state);
|
||||
}
|
||||
SvermClaws.ApplyToUnarmedHit(hit, state);
|
||||
}
|
||||
|
||||
if (rules.VenomOnHit > 0f)
|
||||
|
|
@ -140,13 +139,9 @@ namespace RacesOfValheim
|
|||
|
||||
SvermProgression.SvermRules victimRules = SvermProgression.GetRules(SvermVisuals.GetRenderState(victim));
|
||||
|
||||
// The whole price of the form: out of the shell, a Sverm is an insect. Applied
|
||||
// before the blunt and fire terms so it multiplies everything, not just the two
|
||||
// types the carapace was ever weak to.
|
||||
if (SvermStingerForm.IsActive)
|
||||
{
|
||||
hit.m_damage.Modify(SvermConfig.StingerFragility);
|
||||
}
|
||||
// Ravager Strain no longer touches incoming damage directly - its whole benefit is
|
||||
// the doubled carapace armour applied in Sverm_GetBodyArmor_Patch below, which
|
||||
// Valheim's own armour formula turns into reduced damage the normal way.
|
||||
|
||||
if (victimRules.BluntWeakness != 0f && hit.m_damage.m_blunt > 0f)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ namespace RacesOfValheim
|
|||
/// <summary>How tall the dorsal spines stand, in metres. 0 before they grow.</summary>
|
||||
public float SpineSize;
|
||||
|
||||
public bool StingerMorph; // the Deathsquito form is unlocked
|
||||
public bool RavagerForm; // the Seeker Brute form is unlocked
|
||||
public float BodyScale; // Surrenal Glands
|
||||
public float CarapaceRegenPerSecond;
|
||||
public bool Emberform; // black chitin, red burn, burning claws
|
||||
|
|
@ -94,7 +94,7 @@ namespace RacesOfValheim
|
|||
: state >= SvermConfig.VestigialWingsState ? SvermConfig.SpineSizeSmall
|
||||
: 0f,
|
||||
|
||||
StingerMorph = state >= SvermConfig.StingerMorphState,
|
||||
RavagerForm = state >= SvermConfig.RavagerFormState,
|
||||
|
||||
BodyScale = state >= SvermConfig.SurrenalGlandsState ? SvermConfig.BodyScaleAtQueen : 1f,
|
||||
|
||||
|
|
|
|||
|
|
@ -57,6 +57,10 @@ namespace RacesOfValheim
|
|||
// launches proved a mouth on a shared body is a race between colliders. It has to come
|
||||
// after the nest: its placement gate asks whether one is standing nearby.
|
||||
SvermHiveMarketPiece.Register();
|
||||
|
||||
// Ravager Strain's worn model, stripped down to a costume here because this is the
|
||||
// one safe moment to do it - see SvermRavagerForm.BuildTemplate.
|
||||
SvermRavagerForm.BuildTemplate();
|
||||
}
|
||||
|
||||
public static bool IsSverm()
|
||||
|
|
@ -74,8 +78,8 @@ namespace RacesOfValheim
|
|||
SvermAntennae.Tick(Player.m_localPlayer);
|
||||
|
||||
// Also outside the race guard, and for the same reason: it has to be able to drop the
|
||||
// form and give the player their body back if they stop being a Sverm mid-flight.
|
||||
SvermStingerForm.Tick(Player.m_localPlayer);
|
||||
// form and give the player their body back if they stop being a Sverm mid-transformation.
|
||||
SvermRavagerForm.Tick(Player.m_localPlayer);
|
||||
|
||||
if (Player.m_localPlayer == null || !IsSverm()) return;
|
||||
|
||||
|
|
|
|||
88
JotunnModStub/Sverm/SvermRavagerAttacks.cs
Normal file
88
JotunnModStub/Sverm/SvermRavagerAttacks.cs
Normal file
|
|
@ -0,0 +1,88 @@
|
|||
using UnityEngine;
|
||||
|
||||
namespace RacesOfValheim
|
||||
{
|
||||
/// <summary>
|
||||
/// The Seeker Brute's three real damage profiles - a trigger name and a set of real damage
|
||||
/// numbers, read once from the Brute's own weapons and cached. Nothing is cloned, registered
|
||||
/// or equipped.
|
||||
///
|
||||
/// THIS REPLACES A WHOLE FILE (SvermRavagerWeapons.cs) THAT TRIED TO EQUIP THE REAL ITEMS AND
|
||||
/// LET VALHEIM'S OWN Attack.Start RUN. It fought the game at every turn: Humanoid.
|
||||
/// GetCurrentBlocker routed right-click into a parry because the source items were
|
||||
/// m_blockable; player.InAttack() stopped rooting the player before the visible clip on the
|
||||
/// model had actually finished; wiring a working secondary attack meant cloning and mutating
|
||||
/// Attack objects by hand. None of that is necessary, because this mod already has two
|
||||
/// working examples of "become a creature and attack" - FenrirBehaviors.cs and
|
||||
/// DrakeFormBehavior.cs - and NEITHER of them equips anything. A trigger on the model's own
|
||||
/// Animator plus a timed Physics.OverlapSphere, the same two calls every other transformation
|
||||
/// in this mod already uses, is the whole mechanism. See RavagerFormBehavior.AttackRoutine.
|
||||
/// </summary>
|
||||
public static class SvermRavagerAttacks
|
||||
{
|
||||
public struct Profile
|
||||
{
|
||||
public string Trigger;
|
||||
public HitData.DamageTypes Damage;
|
||||
}
|
||||
|
||||
private static Profile bite;
|
||||
private static Profile ram;
|
||||
private static Profile slam;
|
||||
private static Profile taunt;
|
||||
private static bool read;
|
||||
|
||||
public static Profile Bite { get { EnsureRead(); return bite; } }
|
||||
public static Profile Ram { get { EnsureRead(); return ram; } }
|
||||
public static Profile Slam { get { EnsureRead(); return slam; } }
|
||||
|
||||
/// <summary>
|
||||
/// type=None on the real Brute, so its Attack fields (range/angle/hitbox) were never
|
||||
/// meant to land a hit - only m_attackAnimation and m_damages are trustworthy here, which
|
||||
/// is why the taunt is handled by its own AoE routine rather than folded into
|
||||
/// AttackRoutine's forward-swing shape.
|
||||
/// </summary>
|
||||
public static Profile Taunt { get { EnsureRead(); return taunt; } }
|
||||
|
||||
private static void EnsureRead()
|
||||
{
|
||||
if (read) return;
|
||||
read = true;
|
||||
|
||||
bite = ReadOne(SvermConfig.RavagerBiteWeapon);
|
||||
ram = ReadOne(SvermConfig.RavagerRamWeapon);
|
||||
slam = ReadOne(SvermConfig.RavagerSlamWeapon);
|
||||
taunt = ReadOne(SvermConfig.RavagerTauntWeapon);
|
||||
}
|
||||
|
||||
private static Profile ReadOne(string sourcePrefabName)
|
||||
{
|
||||
GameObject source = Jotunn.Managers.PrefabManager.Cache.GetPrefab<GameObject>(sourcePrefabName);
|
||||
ItemDrop drop = source != null ? source.GetComponent<ItemDrop>() : null;
|
||||
ItemDrop.ItemData.SharedData shared = drop != null ? drop.m_itemData?.m_shared : null;
|
||||
|
||||
if (shared == null)
|
||||
{
|
||||
Jotunn.Logger.LogWarning($"[Sverm] No '{sourcePrefabName}' to read Ravager Strain damage " +
|
||||
"from; that attack will land for nothing.");
|
||||
return default;
|
||||
}
|
||||
|
||||
Profile profile = new Profile
|
||||
{
|
||||
Trigger = shared.m_attack != null ? (shared.m_attack.m_attackAnimation ?? "") : "",
|
||||
Damage = shared.m_damages,
|
||||
};
|
||||
|
||||
Jotunn.Logger.LogInfo($"[Sverm] Ravager Strain reads '{profile.Trigger}' off '{sourcePrefabName}' - " +
|
||||
$"{DumpDamage(profile.Damage)}.");
|
||||
return profile;
|
||||
}
|
||||
|
||||
private static string DumpDamage(HitData.DamageTypes d)
|
||||
{
|
||||
return $"blunt={d.m_blunt:0.#} slash={d.m_slash:0.#} pierce={d.m_pierce:0.#} " +
|
||||
$"chop={d.m_chop:0.#} pickaxe={d.m_pickaxe:0.#}";
|
||||
}
|
||||
}
|
||||
}
|
||||
718
JotunnModStub/Sverm/SvermRavagerForm.cs
Normal file
718
JotunnModStub/Sverm/SvermRavagerForm.cs
Normal file
|
|
@ -0,0 +1,718 @@
|
|||
using HarmonyLib;
|
||||
using Jotunn.Managers;
|
||||
using UnityEngine;
|
||||
|
||||
namespace RacesOfValheim
|
||||
{
|
||||
/// <summary>
|
||||
/// Ravager Strain: from Yagluth on, a Sverm can become a Seeker Brute for two minutes.
|
||||
///
|
||||
/// Replaces the earlier Stinger Morph (a Deathsquito flight form). Players found that form's
|
||||
/// glass-cannon shape too strong for what it cost, so this is the opposite trade: no flight,
|
||||
/// no summons, and the carapace is worth twice as much for as long as the form holds - the
|
||||
/// carapace itself is never removed. Same duration, same cooldown as the form it replaces;
|
||||
/// only the shape of the trade changed.
|
||||
///
|
||||
/// COMBAT FOLLOWS FENRIR AND SKADI'S OWN PATTERN, not Valheim's weapon system. Nothing gets
|
||||
/// equipped. Humanoid.StartAttack is blocked outright for as long as the form is up, and
|
||||
/// RavagerFormBehavior runs its own attack coroutines instead - a trigger on the model's
|
||||
/// Animator, a timed Physics.OverlapSphere, real damage numbers borrowed from
|
||||
/// SvermRavagerAttacks. The earlier version tried to clone the Brute's own weapons and let
|
||||
/// them run through Valheim's real Attack.Start, and it never stopped fighting the game:
|
||||
/// GetCurrentBlocker turning right-click into a parry, player.InAttack() ending before the
|
||||
/// visible clip did, wiring a working secondary attack by hand. Left click bites, right click
|
||||
/// rams, middle click slams, G roars - a short-cooldown AoE around the player rather than a
|
||||
/// fourth forward swing, since the Brute's own taunt was never a hit in the first place.
|
||||
/// </summary>
|
||||
public static class SvermRavagerForm
|
||||
{
|
||||
public static bool IsActive { get; private set; }
|
||||
|
||||
private static GameObject model;
|
||||
private static float expiresAt;
|
||||
private static float nextAllowedAt;
|
||||
|
||||
// Guards the ~1.1s "gpower" gesture in EnterRoutine, and separately the shrink in
|
||||
// ExitRoutine: without them, a second key press mid-gesture would start a second routine
|
||||
// on top of the first, the same double-transform bug Aswid's own isTransformingSequence
|
||||
// flag exists to prevent.
|
||||
private static bool transforming;
|
||||
private static bool exiting;
|
||||
|
||||
private static GameObject template;
|
||||
private static bool templateBuildAttempted;
|
||||
|
||||
// ─── The template ───────────────────────────────────────────────────
|
||||
|
||||
/// <summary>
|
||||
/// Strips the Seeker Brute's borrowed model down to a costume, once, from a moment where
|
||||
/// that is safe to do - the same rule ModelBorrow exists to enforce, and the same one
|
||||
/// WarVultureVisual.BuildTemplate follows for its own borrowed bird. Call it from a
|
||||
/// CreateAllModAssets-time hook; it no-ops on every call after the first.
|
||||
///
|
||||
/// FOUND IN PLAY: the old code instantiated the source's Animator sub-object directly at
|
||||
/// Enter() time, mid-gameplay, and never stripped it. The Brute's own footstep-effect
|
||||
/// script came along for the ride, alive, and spent every frame of the form logging
|
||||
/// "FAiled to find foot:l.backfoot" because the bones it wanted only exist on the
|
||||
/// source's own untouched rig - along with whatever else survived (Character, MonsterAI,
|
||||
/// a Rigidbody, a ZNetView) that this class never meant to carry.
|
||||
///
|
||||
/// DestroyImmediate only, and only because the holder is inactive before the Instantiate
|
||||
/// below: an active clone would Awake every one of those scripts for a frame before the
|
||||
/// strip could remove them, which is the exact bug ModelBorrow's own docstring names.
|
||||
/// Object.Destroy (deferred) would not be safe here for the same reason - by the time it
|
||||
/// actually runs, the frame that mattered has already passed.
|
||||
/// </summary>
|
||||
public static void BuildTemplate()
|
||||
{
|
||||
if (template != null || templateBuildAttempted) return;
|
||||
templateBuildAttempted = true;
|
||||
|
||||
GameObject source = PrefabManager.Cache.GetPrefab<GameObject>(SvermConfig.RavagerCreature);
|
||||
GameObject animated = source != null ? source.GetComponentInChildren<Animator>()?.gameObject : null;
|
||||
|
||||
if (animated == null)
|
||||
{
|
||||
Jotunn.Logger.LogWarning($"[Sverm] No '{SvermConfig.RavagerCreature}' model to build the " +
|
||||
"Ravager Strain template from; the form will run without a body.");
|
||||
return;
|
||||
}
|
||||
|
||||
GameObject holder = new GameObject("SvermRavagerTemplate");
|
||||
Object.DontDestroyOnLoad(holder);
|
||||
holder.SetActive(false); // BEFORE Instantiate: nothing on the copy gets to Awake.
|
||||
|
||||
GameObject copy = Object.Instantiate(animated, holder.transform);
|
||||
copy.name = "model";
|
||||
copy.transform.localPosition = Vector3.zero;
|
||||
copy.transform.localRotation = Quaternion.identity;
|
||||
copy.transform.localScale = animated.transform.localScale;
|
||||
|
||||
// Everything that is not a Renderer or a Transform. Animator is a Behaviour, not a
|
||||
// MonoBehaviour, so it is never touched by the first loop and survives on purpose -
|
||||
// it is the one live thing this costume is allowed to keep.
|
||||
foreach (MonoBehaviour behaviour in copy.GetComponentsInChildren<MonoBehaviour>(true))
|
||||
{
|
||||
if (behaviour != null) Object.DestroyImmediate(behaviour);
|
||||
}
|
||||
foreach (Collider collider in copy.GetComponentsInChildren<Collider>(true))
|
||||
{
|
||||
if (collider != null) Object.DestroyImmediate(collider);
|
||||
}
|
||||
foreach (Rigidbody body in copy.GetComponentsInChildren<Rigidbody>(true))
|
||||
{
|
||||
if (body != null) Object.DestroyImmediate(body);
|
||||
}
|
||||
foreach (ZNetView nview in copy.GetComponentsInChildren<ZNetView>(true))
|
||||
{
|
||||
if (nview != null) Object.DestroyImmediate(nview);
|
||||
}
|
||||
|
||||
template = copy;
|
||||
Jotunn.Logger.LogInfo($"[Sverm] Ravager Strain template built from '{SvermConfig.RavagerCreature}'.");
|
||||
}
|
||||
|
||||
// ─── Driver ──────────────────────────────────────────────────────────
|
||||
|
||||
public static void Tick(Player player)
|
||||
{
|
||||
if (player == null || player != Player.m_localPlayer)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// While the entry gesture (EnterRoutine) or the exit shrink (ExitRoutine) is still
|
||||
// playing, nothing below should react to a key press or a death mid-sequence.
|
||||
if (transforming || exiting) return;
|
||||
|
||||
// Death ends it immediately, and so does ceasing to be a Sverm. Both leave a body
|
||||
// hidden and a bug that is very hard to read, so they are checked before anything
|
||||
// else - and neither one gets the graceful shrink, on purpose: a corpse or a race
|
||||
// change is not the moment for a half-second animation, it is the moment to clean up.
|
||||
if (IsActive && (player.IsDead() || !SvermVisuals.IsSvermPlayer(player)))
|
||||
{
|
||||
Exit(player, spendCooldown: false);
|
||||
return;
|
||||
}
|
||||
|
||||
if (IsActive && Time.time >= expiresAt)
|
||||
{
|
||||
RunExit(player, spendCooldown: true, "The shell recedes.");
|
||||
return;
|
||||
}
|
||||
|
||||
// No manual cancel: the form is short (two minutes) on purpose, and letting G end it
|
||||
// early meant a stray press mid-fight burned the whole cooldown for a form that had
|
||||
// barely started. While IsActive, the key does nothing at all - the timer is the only
|
||||
// way out, same as death or losing the race.
|
||||
if (IsActive) return;
|
||||
|
||||
if (!SvermConfigManagement.RavagerKey.Value.IsDown()) return;
|
||||
if (!SvermVisuals.IsSvermPlayer(player)) return;
|
||||
|
||||
if (!SvermProgression.Current.RavagerForm)
|
||||
{
|
||||
player.Message(MessageHud.MessageType.Center, "The strain has not taken yet.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (Time.time < nextAllowedAt)
|
||||
{
|
||||
player.Message(MessageHud.MessageType.Center, "The strain is spent.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (SvermRace.Instance != null)
|
||||
{
|
||||
SvermRace.Instance.StartCoroutine(EnterRoutine(player));
|
||||
}
|
||||
else
|
||||
{
|
||||
// No host to run the gesture on - a state that should not happen outside a very
|
||||
// early loading frame, but the form working ungestured beats it not working at
|
||||
// all.
|
||||
Enter(player);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The transformation's own animation: the same "gpower" arms-raised gesture Aswid,
|
||||
/// Skadi and Fenrir all borrow for their own transformations (RaceInput's own comment
|
||||
/// names all three), suppressed so it never fires the player's real Guardian Power. The
|
||||
/// actual state change - IsActive, the weapons, the hidden body, the worn model - waits
|
||||
/// out the gesture first, the same order TransformIntoBatRoutine uses in AswidRace.cs.
|
||||
/// </summary>
|
||||
private static System.Collections.IEnumerator EnterRoutine(Player player)
|
||||
{
|
||||
transforming = true;
|
||||
|
||||
ZSyncAnimation zAnim = player.GetComponent<ZSyncAnimation>();
|
||||
if (zAnim != null)
|
||||
{
|
||||
RaceInput.SuppressGuardianPowerBriefly();
|
||||
zAnim.SetTrigger("gpower");
|
||||
}
|
||||
|
||||
yield return new WaitForSeconds(1.1f);
|
||||
|
||||
// The gesture takes over a second; a lot can happen to the player in that window.
|
||||
if (player == null || player != Player.m_localPlayer || player.IsDead() || !SvermVisuals.IsSvermPlayer(player))
|
||||
{
|
||||
transforming = false;
|
||||
yield break;
|
||||
}
|
||||
|
||||
Enter(player);
|
||||
transforming = false;
|
||||
}
|
||||
|
||||
// ─── Enter and leave ─────────────────────────────────────────────────
|
||||
|
||||
private static void Enter(Player player)
|
||||
{
|
||||
IsActive = true;
|
||||
expiresAt = Time.time + SvermConfig.RavagerDurationSeconds;
|
||||
|
||||
player.GetSEMan().AddStatusEffect(SvermConfig.RavagerSE.GetStableHashCode(), true);
|
||||
|
||||
Transform visual = player.transform.Find("Visual");
|
||||
PlayerVisualHider.Hide(visual, "sverm-ravager");
|
||||
|
||||
// BuildTemplate is NOT called from here. Enter() runs from Tick(), inside Update, and
|
||||
// the strip needs DestroyImmediate on an inactive object - safe only from the
|
||||
// CreateAllModAssets-time hook that actually builds this. If that hook never ran, the
|
||||
// template stays null and the form falls back to a bare body below rather than
|
||||
// risking an unsafe strip mid-gameplay.
|
||||
if (template != null)
|
||||
{
|
||||
// A plain Instantiate of an already-stripped template - safe in this context
|
||||
// (mid-gameplay, inside Update) precisely because nothing left on it can Awake
|
||||
// into anything. See BuildTemplate for why that matters.
|
||||
model = Object.Instantiate(template, player.transform.position, player.transform.rotation, player.transform);
|
||||
model.transform.localPosition = Vector3.zero;
|
||||
|
||||
// SCALE COMES FROM THE SOURCE, not from 1 - same reasoning as the old Stinger
|
||||
// Morph. The multiplier defaults to 1 (the Brute's own authored size, full bulk,
|
||||
// by design) and is only there for an eye to correct it against.
|
||||
Vector3 fullScale = template.transform.localScale * SvermConfigManagement.RavagerScale;
|
||||
|
||||
// Grows in rather than popping to full size at once, starting at half scale and
|
||||
// reaching full over half a second - the entrance the transformation itself was
|
||||
// missing. ScaleTween owns the model reference for that half second, not Enter,
|
||||
// so nothing here needs to wait on it.
|
||||
model.transform.localScale = fullScale * 0.5f;
|
||||
if (SvermRace.Instance != null)
|
||||
{
|
||||
SvermRace.Instance.StartCoroutine(ScaleTween(model, fullScale * 0.5f, fullScale, 0.5f));
|
||||
}
|
||||
else
|
||||
{
|
||||
model.transform.localScale = fullScale;
|
||||
}
|
||||
|
||||
// Which way the model faces is a thing only an eye can settle, so it is a config
|
||||
// value and not a constant - same as the old form.
|
||||
model.transform.localRotation = Quaternion.Euler(0f, SvermConfigManagement.RavagerYaw, 0f);
|
||||
|
||||
model.AddComponent<RavagerFormBehavior>();
|
||||
}
|
||||
else
|
||||
{
|
||||
// No model is survivable - the carapace and the armour buff still apply - but it
|
||||
// is worth saying out loud rather than leaving someone to wonder why they turned
|
||||
// into nothing.
|
||||
GameObject bare = new GameObject("SvermRavagerBody");
|
||||
bare.transform.SetParent(player.transform, false);
|
||||
bare.AddComponent<RavagerFormBehavior>();
|
||||
model = bare;
|
||||
}
|
||||
|
||||
PlayEffect(SvermConfig.RavagerMorphInEffects, player.transform.position);
|
||||
|
||||
player.Message(MessageHud.MessageType.Center, "The Ravager Strain takes hold.");
|
||||
}
|
||||
|
||||
private static void PlayEffect(string[] candidates, Vector3 where)
|
||||
{
|
||||
foreach (string name in candidates)
|
||||
{
|
||||
GameObject fx = PrefabManager.Cache.GetPrefab<GameObject>(name);
|
||||
if (fx == null) continue;
|
||||
|
||||
Object.Instantiate(fx, where, Quaternion.identity);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
private static void Exit(Player player, bool spendCooldown)
|
||||
{
|
||||
IsActive = false;
|
||||
|
||||
PlayEffect(SvermConfig.RavagerMorphOutEffects, player.transform.position);
|
||||
|
||||
// Nothing was ever equipped for this form - see the class doc for why - so there is
|
||||
// nothing to hand back here. SvermClawSlot's own throttled pass (Sverm_PlayerUpdate_Patch)
|
||||
// keeps the claws maintained regardless of Ravager Strain, on its own schedule.
|
||||
|
||||
if (model != null)
|
||||
{
|
||||
// FOUND IN PLAY: Object.Destroy is deferred to the end of the frame, so
|
||||
// RavagerFormBehavior's own LateUpdate - the one that re-hides the player's
|
||||
// Visual every frame to kill the equipment-swap flicker - was still firing AFTER
|
||||
// Show() ran a few lines below, undoing it the instant it happened. Nothing called
|
||||
// Show() again afterward, so the player (and whatever VisEquipment had just
|
||||
// rebuilt while unequipping the Ravager weapon above - the carapace included)
|
||||
// stayed hidden for good. SetActive(false) makes Unity skip every further
|
||||
// Update/LateUpdate on this GameObject for the rest of the frame even though the
|
||||
// object itself is not gone yet, which is the only part of "destroyed" that
|
||||
// actually matters here.
|
||||
model.SetActive(false);
|
||||
Object.Destroy(model);
|
||||
model = null;
|
||||
}
|
||||
|
||||
player.GetSEMan().RemoveStatusEffect(SvermConfig.RavagerSE.GetStableHashCode());
|
||||
|
||||
Transform visual = player.transform.Find("Visual");
|
||||
PlayerVisualHider.Show(visual, "sverm-ravager-revert");
|
||||
|
||||
if (spendCooldown)
|
||||
{
|
||||
nextAllowedAt = Time.time + SvermConfig.RavagerCooldownSeconds;
|
||||
player.GetSEMan().AddStatusEffect(SvermConfig.RavagerCdSE.GetStableHashCode(), true);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Kicks off the graceful exit (shrink, then Exit) if there is a host to run it on.</summary>
|
||||
private static void RunExit(Player player, bool spendCooldown, string message)
|
||||
{
|
||||
if (SvermRace.Instance != null)
|
||||
{
|
||||
SvermRace.Instance.StartCoroutine(ExitRoutine(player, spendCooldown, message));
|
||||
}
|
||||
else
|
||||
{
|
||||
Exit(player, spendCooldown);
|
||||
if (message != null) player.Message(MessageHud.MessageType.Center, message);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The mirror of EnterRoutine's grow-in: the model shrinks to half its current scale over
|
||||
/// half a second before Exit() actually tears anything down, so the form has a send-off
|
||||
/// instead of a hard cut. Used for the two GRACEFUL exits only (timeout, manual toggle) -
|
||||
/// death and a race change go through Exit() directly, immediately, on purpose.
|
||||
/// </summary>
|
||||
private static System.Collections.IEnumerator ExitRoutine(Player player, bool spendCooldown, string message)
|
||||
{
|
||||
exiting = true;
|
||||
|
||||
if (model != null)
|
||||
{
|
||||
Vector3 current = model.transform.localScale;
|
||||
yield return ScaleTween(model, current, current * 0.5f, 0.5f);
|
||||
}
|
||||
|
||||
Exit(player, spendCooldown);
|
||||
if (message != null) player.Message(MessageHud.MessageType.Center, message);
|
||||
|
||||
exiting = false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Linear scale from <paramref name="from"/> to <paramref name="to"/> over
|
||||
/// <paramref name="duration"/> seconds. Bails cleanly if the target disappears mid-tween
|
||||
/// rather than assuming it cannot - Exit() is free to destroy the model while this is
|
||||
/// still yielding.
|
||||
/// </summary>
|
||||
private static System.Collections.IEnumerator ScaleTween(GameObject target, Vector3 from, Vector3 to, float duration)
|
||||
{
|
||||
if (target == null) yield break;
|
||||
|
||||
float elapsed = 0f;
|
||||
while (elapsed < duration)
|
||||
{
|
||||
if (target == null) yield break;
|
||||
elapsed += Time.deltaTime;
|
||||
target.transform.localScale = Vector3.Lerp(from, to, elapsed / duration);
|
||||
yield return null;
|
||||
}
|
||||
|
||||
if (target != null) target.transform.localScale = to;
|
||||
}
|
||||
|
||||
// ─── The three attacks ───────────────────────────────────────────────
|
||||
|
||||
/// <summary>
|
||||
/// Blocks Valheim's own attack system outright for the whole form, the same way
|
||||
/// SkadiAttackPatch blocks it for the dragon forms. Whatever the player happens to have
|
||||
/// equipped never swings and never deals damage while this is up; RavagerFormBehavior's
|
||||
/// own coroutines are the only thing that can land a hit.
|
||||
/// </summary>
|
||||
[HarmonyPatch(typeof(Humanoid), "StartAttack")]
|
||||
public static class Sverm_RavagerBlockNativeAttack_Patch
|
||||
{
|
||||
public static bool Prefix(Humanoid __instance)
|
||||
{
|
||||
if (__instance != Player.m_localPlayer) return true;
|
||||
return !IsActive;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>No food, no mead, no potions. The form is meant to be survived, not sustained.</summary>
|
||||
[HarmonyPatch(typeof(Humanoid), "UseItem")]
|
||||
public static class Sverm_RavagerUseItem_Patch
|
||||
{
|
||||
public static bool Prefix(Humanoid __instance)
|
||||
{
|
||||
if (!IsActive) return true;
|
||||
return !(__instance is Player player) || player != Player.m_localPlayer;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Locomotion AND combat, both held on every frame while the form is up - built on the same
|
||||
/// method FenrirFormBehavior and DrakeFormBehavior already use for their own transformations,
|
||||
/// not on Valheim's weapon system. See SvermRavagerAttacks for why.
|
||||
///
|
||||
/// UNLIKE THE OLD STINGER MORPH, this never touches m_debugFly - the whole point of Ravager
|
||||
/// Strain is that it stays on the ground. The player moves exactly as they always do; this
|
||||
/// component only feeds the worn model's own Animator whatever standard Valheim monster
|
||||
/// parameters it actually has - forward_speed and onGround, the same pair DrakeFormBehavior
|
||||
/// drives - plus a jump cue IF the Brute's controller turns out to carry one, checked once at
|
||||
/// Start rather than assumed. Every SetFloat/SetBool/SetTrigger is guarded by that check, the
|
||||
/// same pattern WarVultureVisual.Has uses: driving a parameter name the controller does not
|
||||
/// have is a silent no-op in Unity, but the guard is what makes "does it have one" an answer
|
||||
/// this logs instead of a guess nobody can see.
|
||||
/// </summary>
|
||||
public class RavagerFormBehavior : MonoBehaviour
|
||||
{
|
||||
private Animator anim;
|
||||
private bool hasForwardSpeed;
|
||||
private bool hasOnGround;
|
||||
private bool hasJumpTrigger;
|
||||
private bool hasJumpBool;
|
||||
private bool wasGrounded = true;
|
||||
|
||||
// While true, Update skips both the locomotion sync and any new attack input - the same
|
||||
// gate FenrirFormBehavior's own isAttacking flag uses, and the direct answer to "the
|
||||
// animation has to finish before the Brute can move": nothing here can start moving the
|
||||
// model again, or start a second attack, until the coroutine below clears it.
|
||||
private bool isAttacking;
|
||||
|
||||
// The taunt's own cooldown - short, and tracked separately from the other three, which
|
||||
// have no cooldown of their own beyond their own lock duration.
|
||||
private float nextTauntAt;
|
||||
|
||||
// Every distinct trigger name that has been checked against this Animator and found
|
||||
// present, so PlayAttack does not pass a name to SetTrigger the controller cannot use.
|
||||
private readonly System.Collections.Generic.HashSet<string> knownTriggers = new System.Collections.Generic.HashSet<string>();
|
||||
|
||||
private void Start()
|
||||
{
|
||||
anim = GetComponentInChildren<Animator>();
|
||||
if (anim == null || anim.runtimeAnimatorController == null) return;
|
||||
|
||||
// The same three settings WarVultureVisual.PrepareAnimator uses on its own borrowed
|
||||
// model, for the same reasons. applyRootMotion=false: the slam's clip carries real
|
||||
// baked motion, and left at the default Unity would walk the COSTUME out from under
|
||||
// its wearer - the model has no collider and no gameplay meaning, only the player
|
||||
// does, and the player already moves through Valheim's own code, not an animation
|
||||
// clip. fireEvents=false: attack clips carry animation events aimed at
|
||||
// CharacterAnimEvent, which BuildTemplate already stripped off this model, so left on
|
||||
// every swing would log "has no receiver" for nothing. cullingMode: keeps the model
|
||||
// animating even when it is partly off the bottom of the screen, the way a body
|
||||
// standing close to the camera often is.
|
||||
anim.applyRootMotion = false;
|
||||
anim.fireEvents = false;
|
||||
anim.cullingMode = AnimatorCullingMode.AlwaysAnimate;
|
||||
|
||||
foreach (AnimatorControllerParameter param in anim.parameters)
|
||||
{
|
||||
if (param.type == AnimatorControllerParameterType.Float && param.name == "forward_speed")
|
||||
hasForwardSpeed = true;
|
||||
else if (param.type == AnimatorControllerParameterType.Bool && param.name == "onGround")
|
||||
hasOnGround = true;
|
||||
else if (param.type == AnimatorControllerParameterType.Trigger && param.name == "jump")
|
||||
hasJumpTrigger = true;
|
||||
else if (param.type == AnimatorControllerParameterType.Bool && param.name == "jump")
|
||||
hasJumpBool = true;
|
||||
else if (param.type == AnimatorControllerParameterType.Trigger)
|
||||
knownTriggers.Add(param.name);
|
||||
}
|
||||
|
||||
Jotunn.Logger.LogInfo($"[Sverm] Ravager Strain model animator: forward_speed={hasForwardSpeed}, " +
|
||||
$"onGround={hasOnGround}, jump=" +
|
||||
(hasJumpTrigger ? "trigger" : hasJumpBool ? "bool" : "none") + ".");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// FOUND IN PLAY: the real body flickered into view on every equipment change elsewhere
|
||||
/// in the game (a nearby player's gear, a tamed animal, anything that shares
|
||||
/// VisEquipment's rebuild path) - PlayerVisualHider's own comment already says gear
|
||||
/// changes make hidden things visible again, which is why it re-sweeps on a timer rather
|
||||
/// than hiding once. That timer is 0.25s, long enough to be noticed.
|
||||
///
|
||||
/// LateUpdate, not Update: Unity runs every component's Update before any component's
|
||||
/// LateUpdate in a given frame, so this always runs after whatever rebuilt visuals
|
||||
/// earlier in the same frame, rather than racing it. Re-hiding every single frame the
|
||||
/// form is up closes the gap the 0.25s timer leaves open, without touching
|
||||
/// PlayerVisualHider's own interval, which every other race's hidden body still relies on.
|
||||
/// </summary>
|
||||
private void LateUpdate()
|
||||
{
|
||||
Player player = Player.m_localPlayer;
|
||||
if (player == null) return;
|
||||
|
||||
Transform visual = player.transform.Find("Visual");
|
||||
PlayerVisualHider.Hide(visual, "sverm-ravager");
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
Player player = Player.m_localPlayer;
|
||||
if (player == null || player.IsDead()) return;
|
||||
|
||||
if (isAttacking) return;
|
||||
|
||||
bool grounded = player.IsOnGround();
|
||||
|
||||
if (hasForwardSpeed)
|
||||
{
|
||||
Vector3 velocity = player.GetVelocity();
|
||||
velocity.y = 0f;
|
||||
anim.SetFloat("forward_speed", velocity.magnitude);
|
||||
}
|
||||
|
||||
if (hasOnGround) anim.SetBool("onGround", grounded);
|
||||
|
||||
if (hasJumpTrigger)
|
||||
{
|
||||
// The rising edge only, so a trigger fires once per jump rather than once per
|
||||
// frame spent airborne.
|
||||
if (!grounded && wasGrounded) anim.SetTrigger("jump");
|
||||
}
|
||||
else if (hasJumpBool)
|
||||
{
|
||||
anim.SetBool("jump", !grounded);
|
||||
}
|
||||
|
||||
wasGrounded = grounded;
|
||||
|
||||
if (!RaceInput.Allowed || !grounded) return;
|
||||
|
||||
// Right click rams, left click bites, middle click slams. All three read raw
|
||||
// UnityEngine.Input rather than going anywhere near Humanoid.StartAttack, which
|
||||
// Sverm_RavagerBlockNativeAttack_Patch refuses outright for the whole form - see the
|
||||
// class doc for why that turned out to be the only reliable option.
|
||||
if (Input.GetMouseButtonDown(1))
|
||||
{
|
||||
StartCoroutine(AttackRoutine(SvermRavagerAttacks.Ram, 2f, 0.3f, 0.7f));
|
||||
}
|
||||
else if (Input.GetMouseButtonDown(0))
|
||||
{
|
||||
StartCoroutine(AttackRoutine(SvermRavagerAttacks.Bite, 2f, 0.3f, 0.6f));
|
||||
}
|
||||
else if (Input.GetMouseButtonDown(2))
|
||||
{
|
||||
StartCoroutine(AttackRoutine(SvermRavagerAttacks.Slam, 1.2f, 0.4f, 1.0f));
|
||||
}
|
||||
else if (SvermConfigManagement.RavagerKey.Value.IsDown() && Time.time >= nextTauntAt)
|
||||
{
|
||||
nextTauntAt = Time.time + SvermConfig.RavagerTauntCooldownSeconds;
|
||||
StartCoroutine(TauntRoutine());
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// One swing: play the clip, wait for the moment it should land, hit whatever is there,
|
||||
/// then hold isAttacking until the swing is fully spent. FenrirFormBehavior.ClawRoutine in
|
||||
/// every particular except the damage itself, which here is the Brute's own real numbers
|
||||
/// (SvermRavagerAttacks) instead of one tuned float.
|
||||
/// </summary>
|
||||
private System.Collections.IEnumerator AttackRoutine(SvermRavagerAttacks.Profile profile, float radius,
|
||||
float hitDelay, float lockDuration)
|
||||
{
|
||||
isAttacking = true;
|
||||
|
||||
if (hasForwardSpeed) anim.SetFloat("forward_speed", 0f);
|
||||
|
||||
if (!string.IsNullOrEmpty(profile.Trigger) && knownTriggers.Contains(profile.Trigger))
|
||||
{
|
||||
anim.SetTrigger(profile.Trigger);
|
||||
}
|
||||
|
||||
yield return new WaitForSeconds(hitDelay);
|
||||
|
||||
ExecuteDamage(profile, radius);
|
||||
|
||||
float remaining = lockDuration - hitDelay;
|
||||
if (remaining > 0f) yield return new WaitForSeconds(remaining);
|
||||
|
||||
isAttacking = false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The taunt, played as a short-cooldown AoE around the player rather than a forward
|
||||
/// swing - the roar reaches out in every direction, so the sphere is centred on the
|
||||
/// player instead of offset ahead of them the way AttackRoutine's three do. Deliberately
|
||||
/// silent: no message, no status effect, nothing in a corner of the screen - just the
|
||||
/// animation, the sound if one resolves, and the hit.
|
||||
/// </summary>
|
||||
private System.Collections.IEnumerator TauntRoutine()
|
||||
{
|
||||
isAttacking = true;
|
||||
|
||||
SvermRavagerAttacks.Profile profile = SvermRavagerAttacks.Taunt;
|
||||
|
||||
if (hasForwardSpeed) anim.SetFloat("forward_speed", 0f);
|
||||
|
||||
if (!string.IsNullOrEmpty(profile.Trigger) && knownTriggers.Contains(profile.Trigger))
|
||||
{
|
||||
anim.SetTrigger(profile.Trigger);
|
||||
}
|
||||
|
||||
PlaySound(SvermConfig.RavagerTauntSoundEffects);
|
||||
|
||||
yield return new WaitForSeconds(0.3f);
|
||||
|
||||
Player player = Player.m_localPlayer;
|
||||
if (player != null)
|
||||
{
|
||||
ApplyDamageInSphere(player.transform.position + Vector3.up, SvermConfig.RavagerTauntRadius, profile.Damage);
|
||||
}
|
||||
|
||||
yield return new WaitForSeconds(0.4f);
|
||||
|
||||
isAttacking = false;
|
||||
}
|
||||
|
||||
/// <summary>Tries each candidate in order and plays the first that resolves, same as SvermRavagerForm.PlayEffect.</summary>
|
||||
private static void PlaySound(string[] candidates)
|
||||
{
|
||||
Player player = Player.m_localPlayer;
|
||||
if (player == null) return;
|
||||
|
||||
foreach (string name in candidates)
|
||||
{
|
||||
GameObject prefab = Jotunn.Managers.PrefabManager.Cache.GetPrefab<GameObject>(name);
|
||||
if (prefab == null) continue;
|
||||
|
||||
Object.Instantiate(prefab, player.transform.position, Quaternion.identity);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// FenrirBehaviors.ExecuteClawDamage, unchanged in shape: a sphere swept against the same
|
||||
/// broad layer mask every melee form in this mod already uses.
|
||||
/// </summary>
|
||||
private void ExecuteDamage(SvermRavagerAttacks.Profile profile, float radius)
|
||||
{
|
||||
Player player = Player.m_localPlayer;
|
||||
if (player == null) return;
|
||||
|
||||
float reach = SvermConfigManagement.RavagerAttackOffset;
|
||||
Vector3 attackPoint = player.transform.position + player.transform.forward * reach + Vector3.up;
|
||||
ApplyDamageInSphere(attackPoint, radius, profile.Damage);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The actual sweep, shared by every attack this form has (the three forward swings and
|
||||
/// the taunt's own AoE) - only the sphere's centre and radius differ between them.
|
||||
///
|
||||
/// 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
|
||||
/// 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'.
|
||||
/// </summary>
|
||||
private static void ApplyDamageInSphere(Vector3 center, float radius, HitData.DamageTypes damage)
|
||||
{
|
||||
Player player = Player.m_localPlayer;
|
||||
if (player == null) return;
|
||||
|
||||
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(center, radius, layerMask);
|
||||
var hitObjects = new System.Collections.Generic.HashSet<GameObject>();
|
||||
|
||||
foreach (Collider hit in hits)
|
||||
{
|
||||
if (hit.gameObject == player.gameObject) continue;
|
||||
if (hit.attachedRigidbody != null && hit.attachedRigidbody.gameObject == player.gameObject) continue;
|
||||
|
||||
IDestructible target = hit.GetComponentInParent<IDestructible>();
|
||||
if (target == null) continue;
|
||||
|
||||
if (target is Character characterTarget && characterTarget == player) continue;
|
||||
|
||||
GameObject targetObj = (target as MonoBehaviour)?.gameObject;
|
||||
if (targetObj != null)
|
||||
{
|
||||
if (hitObjects.Contains(targetObj)) continue;
|
||||
hitObjects.Add(targetObj);
|
||||
}
|
||||
|
||||
Vector3 targetCenter = hit.bounds.center;
|
||||
Vector3 dirToTarget = (targetCenter - player.transform.position).normalized;
|
||||
|
||||
HitData hitData = new HitData();
|
||||
hitData.m_damage = damage;
|
||||
hitData.m_point = targetCenter;
|
||||
hitData.m_dir = dirToTarget;
|
||||
hitData.m_pushForce = 40f;
|
||||
hitData.m_skill = Skills.SkillType.Swords;
|
||||
hitData.m_dodgeable = true;
|
||||
hitData.m_blockable = true;
|
||||
hitData.m_hitType = HitData.HitType.PlayerHit;
|
||||
hitData.m_toolTier = 100;
|
||||
hitData.SetAttacker(player);
|
||||
|
||||
target.Damage(hitData);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -92,29 +92,37 @@ namespace RacesOfValheim
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Stinger Morph's cooldown. Purely a marker with a countdown, the way
|
||||
/// Ravager Strain's cooldown. Purely a marker with a countdown, the way
|
||||
/// SE_DvergarAbilityCooldown is: Valheim prints the remaining time of any effect with a m_ttl,
|
||||
/// so the HUD comes for free.
|
||||
/// </summary>
|
||||
public class SE_SvermStingerCooldown : StatusEffect
|
||||
public class SE_SvermRavagerCooldown : StatusEffect
|
||||
{
|
||||
public override void Setup(Character character)
|
||||
{
|
||||
base.Setup(character);
|
||||
m_name = "Stinger Morph Cooldown";
|
||||
m_tooltip = "The wings are spent. They will carry you again soon.";
|
||||
m_ttl = SvermConfig.StingerCooldownSeconds;
|
||||
m_name = "Ravager Strain Cooldown";
|
||||
m_tooltip = "The strain is spent. It will take again soon.";
|
||||
m_ttl = SvermConfig.RavagerCooldownSeconds;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Held while the Deathsquito form is up, so anything can ask "am I a bug right now".</summary>
|
||||
public class SE_SvermStingerForm : StatusEffect
|
||||
/// <summary>
|
||||
/// Held while the Seeker Brute form is up, so anything can ask "am I wearing the Brute right
|
||||
/// now". FOUND IN PLAY: without m_ttl, this icon showed with no countdown at all while the
|
||||
/// cooldown icon right next to it did - the same top-right corner telling two different
|
||||
/// stories about how a timer works. Setting it means the HUD counts the form down to zero the
|
||||
/// same way it already counts the cooldown down, and the two hand off from one to the other
|
||||
/// exactly as SvermRavagerForm.Exit/Enter's own timers do.
|
||||
/// </summary>
|
||||
public class SE_SvermRavagerForm : StatusEffect
|
||||
{
|
||||
public override void Setup(Character character)
|
||||
{
|
||||
base.Setup(character);
|
||||
m_name = "Stinger Morph";
|
||||
m_tooltip = "Wings, a needle, and nothing to hide behind.";
|
||||
m_name = "Ravager Strain";
|
||||
m_tooltip = "The shell doubles, and nothing that hits it lands the same again.";
|
||||
m_ttl = SvermConfig.RavagerDurationSeconds;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -136,15 +144,15 @@ namespace RacesOfValheim
|
|||
ItemManager.Instance.AddStatusEffect(customStats);
|
||||
StatsSE = customStats.StatusEffect as SE_SvermStats;
|
||||
|
||||
var form = ScriptableObject.CreateInstance<SE_SvermStingerForm>();
|
||||
form.name = SvermConfig.StingerSE;
|
||||
form.m_name = "Stinger Morph";
|
||||
var form = ScriptableObject.CreateInstance<SE_SvermRavagerForm>();
|
||||
form.name = SvermConfig.RavagerSE;
|
||||
form.m_name = "Ravager Strain";
|
||||
form.m_icon = icon;
|
||||
ItemManager.Instance.AddStatusEffect(new CustomStatusEffect(form, fixReference: false));
|
||||
|
||||
var cooldown = ScriptableObject.CreateInstance<SE_SvermStingerCooldown>();
|
||||
cooldown.name = SvermConfig.StingerCdSE;
|
||||
cooldown.m_name = "Stinger Morph Cooldown";
|
||||
var cooldown = ScriptableObject.CreateInstance<SE_SvermRavagerCooldown>();
|
||||
cooldown.name = SvermConfig.RavagerCdSE;
|
||||
cooldown.m_name = "Ravager Strain Cooldown";
|
||||
cooldown.m_icon = icon;
|
||||
ItemManager.Instance.AddStatusEffect(new CustomStatusEffect(cooldown, fixReference: false));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,384 +0,0 @@
|
|||
using HarmonyLib;
|
||||
using Jotunn.Managers;
|
||||
using UnityEngine;
|
||||
|
||||
namespace RacesOfValheim
|
||||
{
|
||||
/// <summary>
|
||||
/// Stinger Morph: from Yagluth on, a Sverm can become a Deathsquito for two minutes.
|
||||
///
|
||||
/// It is the one thing in the race that is not armour. Everything else the Sverm has says
|
||||
/// "stand there and survive"; this says the opposite, and it is deliberate that the two do not
|
||||
/// overlap - in form there is no carapace, no claws, no inventory and no hammer, only a needle
|
||||
/// and the ability to leave. A glass cannon that flies is the role the tank was missing.
|
||||
///
|
||||
/// Built on two things that already work: BatFormBehavior for flight (Valheim's own
|
||||
/// m_debugFly, held on every frame) and PlayerVisualHider for swapping the body out. The
|
||||
/// duration and cooldown follow FenrirProgression.FormRules' shape - a timer and a status
|
||||
/// effect the HUD can count down - without borrowing that race's tables.
|
||||
/// </summary>
|
||||
public static class SvermStingerForm
|
||||
{
|
||||
public static bool IsActive { get; private set; }
|
||||
|
||||
private static GameObject model;
|
||||
private static float expiresAt;
|
||||
private static float nextAllowedAt;
|
||||
|
||||
private static HitData.DamageTypes stingerDamage;
|
||||
private static bool stingerDamageRead;
|
||||
|
||||
// ─── Driver ──────────────────────────────────────────────────────────
|
||||
|
||||
public static void Tick(Player player)
|
||||
{
|
||||
if (player == null || player != Player.m_localPlayer)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Death ends it immediately, and so does ceasing to be a Sverm. Both leave a body
|
||||
// hidden and a bug that is very hard to read, so they are checked before anything else.
|
||||
if (IsActive && (player.IsDead() || !SvermVisuals.IsSvermPlayer(player)))
|
||||
{
|
||||
Exit(player, spendCooldown: false);
|
||||
return;
|
||||
}
|
||||
|
||||
if (IsActive && Time.time >= expiresAt)
|
||||
{
|
||||
Exit(player, spendCooldown: true);
|
||||
player.Message(MessageHud.MessageType.Center, "The wings fold away.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!SvermConfigManagement.StingerKey.Value.IsDown()) return;
|
||||
if (!SvermVisuals.IsSvermPlayer(player)) return;
|
||||
|
||||
if (IsActive)
|
||||
{
|
||||
Exit(player, spendCooldown: true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!SvermProgression.Current.StingerMorph)
|
||||
{
|
||||
player.Message(MessageHud.MessageType.Center, "Your wings are still vestigial.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (Time.time < nextAllowedAt)
|
||||
{
|
||||
player.Message(MessageHud.MessageType.Center, "The wings are spent.");
|
||||
return;
|
||||
}
|
||||
|
||||
Enter(player);
|
||||
}
|
||||
|
||||
// ─── Enter and leave ─────────────────────────────────────────────────
|
||||
|
||||
private static void Enter(Player player)
|
||||
{
|
||||
// THE CLAWS STAY ON, and everything else comes off.
|
||||
//
|
||||
// The first version emptied the hands completely and the form could not attack: with
|
||||
// nothing equipped there is no weapon to swing, and Valheim's bare fist is not the
|
||||
// thing this form is supposed to be throwing. Leaving the Chitin Claws equipped makes the
|
||||
// sting an ordinary weapon attack - which works - and costs nothing visually, because
|
||||
// the whole body is hidden a line later. Fist weapons report Skills.SkillType.Unarmed,
|
||||
// so the damage patch still recognises the blow and swaps the deathsquito's figure in.
|
||||
ItemDrop.ItemData held = Traverse.Create((Humanoid)player).Field<ItemDrop.ItemData>("m_rightItem").Value;
|
||||
if (held != null && !SvermClawSlot.IsClaws(held))
|
||||
{
|
||||
player.UnequipItem(held, false);
|
||||
SvermClawSlot.Maintain(player); // hands back the claws in its place
|
||||
}
|
||||
|
||||
IsActive = true;
|
||||
expiresAt = Time.time + SvermConfig.StingerDurationSeconds;
|
||||
|
||||
player.GetSEMan().AddStatusEffect(SvermConfig.StingerSE.GetStableHashCode(), true);
|
||||
|
||||
Transform visual = player.transform.Find("Visual");
|
||||
PlayerVisualHider.Hide(visual, "sverm-stinger");
|
||||
|
||||
GameObject source = PrefabManager.Cache.GetPrefab<GameObject>(SvermConfig.StingerCreature);
|
||||
GameObject animated = source != null ? source.GetComponentInChildren<Animator>()?.gameObject : null;
|
||||
|
||||
if (animated != null)
|
||||
{
|
||||
model = Object.Instantiate(animated, player.transform.position, player.transform.rotation, player.transform);
|
||||
model.transform.localPosition = Vector3.zero;
|
||||
|
||||
// SCALE COMES FROM THE SOURCE, not from 1.
|
||||
//
|
||||
// Forcing Vector3.one is what the Aswid does for the bat and it happens to be
|
||||
// right there, because a bat's animated child is authored at 1. A deathsquito's is
|
||||
// not - forcing 1 blew it up to something the size of a house. Keeping the source's
|
||||
// own scale means the model arrives the size the game draws it, and the multiplier
|
||||
// is there only for taste.
|
||||
model.transform.localScale = animated.transform.localScale * SvermConfigManagement.StingerScale;
|
||||
|
||||
// AND IT FACES THE WRONG WAY without this. The creature's own forward is not the
|
||||
// player's, so the model arrived looking back at the camera. Which way to turn it
|
||||
// is a thing only an eye can settle, so it is a config value and not a constant.
|
||||
model.transform.localRotation = Quaternion.Euler(0f, SvermConfigManagement.StingerYaw, 0f);
|
||||
|
||||
model.AddComponent<StingerFormBehavior>();
|
||||
}
|
||||
else
|
||||
{
|
||||
// No model is survivable - you fly as an invisible insect - but it is worth saying
|
||||
// out loud rather than leaving someone to wonder why they turned into nothing.
|
||||
Jotunn.Logger.LogWarning($"[Sverm] No '{SvermConfig.StingerCreature}' model to wear; " +
|
||||
"Stinger Morph flies without a body.");
|
||||
GameObject bare = new GameObject("SvermStingerFlight");
|
||||
bare.transform.SetParent(player.transform, false);
|
||||
bare.AddComponent<StingerFormBehavior>();
|
||||
model = bare;
|
||||
}
|
||||
|
||||
PlayEffect(SvermConfig.MorphInEffects, player.transform.position);
|
||||
SummonEscort(player);
|
||||
|
||||
player.Message(MessageHud.MessageType.Center, "You take to the air.");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Two deathsquitoes, tamed, that outlive the form by a minute.
|
||||
///
|
||||
/// They are NOT tied to the form's lifetime and that is the point: the form ends where it
|
||||
/// ends, usually mid-air, and the player becomes a slow armoured thing halfway through a
|
||||
/// fall. The escort covers exactly that minute and then dies on its own.
|
||||
///
|
||||
/// Tamed rather than merely friendly, because tamed is the one state every part of the
|
||||
/// game already understands - they will not be attacked by the player, they will not
|
||||
/// attack the player, and BaseAI already knows to fight what fights them.
|
||||
/// </summary>
|
||||
private static void SummonEscort(Player player)
|
||||
{
|
||||
GameObject prefab = PrefabManager.Cache.GetPrefab<GameObject>(SvermConfig.StingerCreature);
|
||||
if (prefab == null) return;
|
||||
|
||||
for (int i = 0; i < SvermConfig.EscortCount; i++)
|
||||
{
|
||||
// Spread them apart, and above: spawning two creatures inside each other and
|
||||
// inside the player is how you get three things shoved through the floor.
|
||||
float angle = 360f / Mathf.Max(1, SvermConfig.EscortCount) * i;
|
||||
Vector3 offset = Quaternion.Euler(0f, angle, 0f) * Vector3.forward * SvermConfig.EscortSpawnSpread;
|
||||
Vector3 where = player.transform.position + offset + Vector3.up * 1.5f;
|
||||
|
||||
GameObject spawned = Object.Instantiate(prefab, where, Quaternion.identity);
|
||||
if (spawned == null) continue;
|
||||
|
||||
Character character = spawned.GetComponent<Character>();
|
||||
if (character != null) character.SetTamed(true);
|
||||
|
||||
// Nothing to farm: an escort that dropped trophies would be a deathsquito printer
|
||||
// on an eight minute cooldown. Same reasoning as the thralls' stripped drop tables.
|
||||
CharacterDrop drop = spawned.GetComponent<CharacterDrop>();
|
||||
if (drop != null) Object.Destroy(drop);
|
||||
|
||||
spawned.AddComponent<SvermEscortLife>().Expires = Time.time + SvermConfig.EscortLifetimeSeconds;
|
||||
}
|
||||
}
|
||||
|
||||
private static void PlayEffect(string[] candidates, Vector3 where)
|
||||
{
|
||||
foreach (string name in candidates)
|
||||
{
|
||||
GameObject fx = PrefabManager.Cache.GetPrefab<GameObject>(name);
|
||||
if (fx == null) continue;
|
||||
|
||||
Object.Instantiate(fx, where, Quaternion.identity);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
private static void Exit(Player player, bool spendCooldown)
|
||||
{
|
||||
IsActive = false;
|
||||
|
||||
PlayEffect(SvermConfig.MorphOutEffects, player.transform.position);
|
||||
|
||||
// The escort is deliberately NOT dismissed here. It has its own minute left to run.
|
||||
|
||||
if (model != null)
|
||||
{
|
||||
Object.Destroy(model);
|
||||
model = null;
|
||||
}
|
||||
|
||||
player.GetSEMan().RemoveStatusEffect(SvermConfig.StingerSE.GetStableHashCode());
|
||||
|
||||
Transform visual = player.transform.Find("Visual");
|
||||
PlayerVisualHider.Show(visual, "sverm-stinger-revert");
|
||||
|
||||
if (spendCooldown)
|
||||
{
|
||||
nextAllowedAt = Time.time + SvermConfig.StingerCooldownSeconds;
|
||||
player.GetSEMan().AddStatusEffect(SvermConfig.StingerCdSE.GetStableHashCode(), true);
|
||||
}
|
||||
}
|
||||
|
||||
// ─── The sting ───────────────────────────────────────────────────────
|
||||
|
||||
/// <summary>
|
||||
/// The Deathsquito's own damage, read off the creature rather than invented.
|
||||
///
|
||||
/// Vanilla's deathsquito hits harder per blow than anything else in the Plains, and that
|
||||
/// number is the entire reason the form is worth its cooldown. Reading it means the form
|
||||
/// tracks whatever the game says a deathsquito is worth, forever.
|
||||
/// </summary>
|
||||
public static HitData.DamageTypes GetStingDamage()
|
||||
{
|
||||
if (stingerDamageRead) return stingerDamage;
|
||||
|
||||
GameObject creature = PrefabManager.Cache.GetPrefab<GameObject>(SvermConfig.StingerCreature);
|
||||
Humanoid humanoid = creature != null ? creature.GetComponent<Humanoid>() : null;
|
||||
|
||||
if (humanoid != null && humanoid.m_defaultItems != null)
|
||||
{
|
||||
foreach (GameObject weapon in humanoid.m_defaultItems)
|
||||
{
|
||||
ItemDrop drop = weapon != null ? weapon.GetComponent<ItemDrop>() : null;
|
||||
if (drop == null || drop.m_itemData == null || drop.m_itemData.m_shared == null) continue;
|
||||
|
||||
stingerDamage = drop.m_itemData.m_shared.m_damages;
|
||||
stingerDamageRead = true;
|
||||
Jotunn.Logger.LogInfo($"[Sverm] Stinger reads {stingerDamage.m_pierce:0.#} pierce " +
|
||||
$"off '{weapon.name}'.");
|
||||
return stingerDamage;
|
||||
}
|
||||
}
|
||||
|
||||
Jotunn.Logger.LogWarning($"[Sverm] Could not read a weapon off '{SvermConfig.StingerCreature}'; " +
|
||||
"the sting falls back to the Chitin Claws.");
|
||||
stingerDamageRead = true;
|
||||
return stingerDamage; // all zeroes: the damage patch then leaves the claw values alone
|
||||
}
|
||||
|
||||
// ─── What the form may not do ────────────────────────────────────────
|
||||
|
||||
/// <summary>
|
||||
/// No weapons in form, which also means no hammer - so "cannot build" needs no patch of
|
||||
/// its own, it falls out of having nothing to build with.
|
||||
/// </summary>
|
||||
[HarmonyPatch(typeof(Humanoid), nameof(Humanoid.EquipItem))]
|
||||
public static class Sverm_StingerEquip_Patch
|
||||
{
|
||||
public static bool Prefix(Humanoid __instance, ItemDrop.ItemData item, ref bool __result)
|
||||
{
|
||||
if (!IsActive) return true;
|
||||
|
||||
Player player = __instance as Player;
|
||||
if (player == null || player != Player.m_localPlayer) return true;
|
||||
|
||||
// The claws are the exception, and they have to be: they are what the form
|
||||
// attacks with, and SvermClawSlot.Maintain hands them back whenever the hands go
|
||||
// empty. Refusing them here would fight that loop every half second.
|
||||
if (SvermClawSlot.IsClaws(item)) return true;
|
||||
|
||||
player.Message(MessageHud.MessageType.Center, "An insect carries nothing.");
|
||||
__result = false;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>No food, no mead, no potions. The form is meant to be survived, not sustained.</summary>
|
||||
[HarmonyPatch(typeof(Humanoid), "UseItem")]
|
||||
public static class Sverm_StingerUseItem_Patch
|
||||
{
|
||||
public static bool Prefix(Humanoid __instance)
|
||||
{
|
||||
if (!IsActive) return true;
|
||||
return !(__instance is Player player) || player != Player.m_localPlayer;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// An escort deathsquito's own clock.
|
||||
///
|
||||
/// It dies rather than vanishing - Character.Damage with enough to finish it - so the death
|
||||
/// plays its effects and reads as the summon running out rather than as a creature popping out
|
||||
/// of existence. The drop table was stripped at spawn, so dying costs the world nothing.
|
||||
/// </summary>
|
||||
public class SvermEscortLife : MonoBehaviour
|
||||
{
|
||||
public float Expires;
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (Time.time < Expires) return;
|
||||
|
||||
Character character = GetComponent<Character>();
|
||||
if (character == null || character.IsDead())
|
||||
{
|
||||
// ZNetScene.Destroy, NEVER Object.Destroy, and this line was the teleport crash.
|
||||
//
|
||||
// An escort is a real networked creature, and ZNetView.OnDestroy - read out of the
|
||||
// assembly, not assumed - only releases asset references: it does not take the
|
||||
// object out of ZNetScene.m_instances. A plain Object.Destroy therefore left the
|
||||
// scene holding a dead ZNetView, and the next time the world unloaded around the
|
||||
// player, which is exactly what a teleport is, ZNetScene.RemoveObjects walked that
|
||||
// entry and threw. See ZNetSceneOrphanPatch.cs for the whole chain.
|
||||
if (ZNetScene.instance != null) ZNetScene.instance.Destroy(gameObject);
|
||||
else Destroy(gameObject);
|
||||
return;
|
||||
}
|
||||
|
||||
HitData hit = new HitData();
|
||||
hit.m_damage.m_damage = character.GetMaxHealth() * 10f;
|
||||
hit.m_point = character.GetCenterPoint();
|
||||
character.Damage(hit);
|
||||
|
||||
enabled = false; // the death takes a moment; do not queue another blow every frame
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Flight, held on every frame.
|
||||
///
|
||||
/// m_debugFly is Valheim's own free-flight switch and it is re-asserted every Update rather
|
||||
/// than set once, because plenty of things in the game turn it back off - the same reason
|
||||
/// BatFormBehavior does it that way. OnDestroy putting it back is what stops a Sverm from
|
||||
/// walking on air after the form ends.
|
||||
/// </summary>
|
||||
public class StingerFormBehavior : MonoBehaviour
|
||||
{
|
||||
private Animator anim;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
anim = GetComponentInChildren<Animator>();
|
||||
SetFly(true);
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (Player.m_localPlayer == null || Player.m_localPlayer.IsDead()) return;
|
||||
|
||||
SetFly(true);
|
||||
|
||||
if (anim == null) return;
|
||||
|
||||
Vector3 velocity = Player.m_localPlayer.GetVelocity();
|
||||
velocity.y = 0f;
|
||||
anim.SetFloat("forward_speed", velocity.magnitude);
|
||||
anim.SetBool("flying", true);
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
SetFly(false);
|
||||
}
|
||||
|
||||
private static void SetFly(bool on)
|
||||
{
|
||||
if (Player.m_localPlayer == null) return;
|
||||
Traverse.Create(Player.m_localPlayer).Field("m_debugFly").SetValue(on);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue