Merge branch 'war-vulture' into main
Brings in the Sverm race, the War Vulture flying mount, and Skadi's Crystal Golem (replacing the Hidden Hollow). Resolved conflicts: AswidVisuals.cs took war-vulture's skeleton-eye-light rewrite with main's attach/attack/sleep timing guard re-applied on top, and RaceCompendium.cs kept main's rewritten race entries while folding in war-vulture's Sverm/War Vulture pages and the new Claws paragraphs for Aswid and Fenrir.
This commit is contained in:
commit
58f70f1a4c
57 changed files with 11362 additions and 1102 deletions
|
|
@ -48,12 +48,6 @@ namespace RacesOfValheim
|
|||
// ─── Passive combat ──────────────────────────────────────────────────
|
||||
public static ConfigEntry<float> BonusFrostDamagePerState;
|
||||
|
||||
// ─── Skadis Nokkel / the hidden hollow ───────────────────────────────
|
||||
public static ConfigEntry<float> HollowCooldown;
|
||||
public static ConfigEntry<float> HollowPortalCloseDelay;
|
||||
public static ConfigEntry<float> HollowPortalSpawnDistance;
|
||||
public static ConfigEntry<float> HollowEntryHeight;
|
||||
|
||||
// ─── Dragon forms: scale ─────────────────────────────────────────────
|
||||
public static ConfigEntry<float> DrakeScale;
|
||||
public static ConfigEntry<float> ModerScale;
|
||||
|
|
@ -108,16 +102,6 @@ namespace RacesOfValheim
|
|||
BonusFrostDamagePerState = config.Bind(combat, "Bonus Frost Damage Per State", 2f,
|
||||
new ConfigDescription("Flat frost damage added to every hit the player lands, multiplied by the current progression state.", new AcceptableValueRange<float>(0f, 10f)));
|
||||
|
||||
const string hollow = "Skadi - Hidden Hollow";
|
||||
HollowCooldown = config.Bind(hollow, "Cooldown", 120f,
|
||||
new ConfigDescription("Seconds between openings of the hollow. This is the only brake on Skadis Nokkel - it costs no stamina, eitr or health - and it never applies to LEAVING: stepping in and changing your mind must not lock you in.", new AcceptableValueRange<float>(0f, 600f)));
|
||||
HollowPortalCloseDelay = config.Bind(hollow, "Portal Close Delay", 5f,
|
||||
new ConfigDescription("Seconds the portal pair lingers after the player comes back out. Until then both ends simply stand there - unlike the Trenta portal, this one has no lifetime of its own.", new AcceptableValueRange<float>(0f, 60f)));
|
||||
HollowPortalSpawnDistance = config.Bind(hollow, "Portal Spawn Distance", 2f,
|
||||
new ConfigDescription("Metres in front of the player the outside end of the portal appears.", new AcceptableValueRange<float>(0.5f, 10f)));
|
||||
HollowEntryHeight = config.Bind(hollow, "Entry Height", 1f,
|
||||
new ConfigDescription("Height above the claimed troll cave's own origin that the inner portal stands at. Raise it if arriving ever puts the player inside the ground.", new AcceptableValueRange<float>(0f, 20f)));
|
||||
|
||||
const string spell = "Skadi - Cold Spell";
|
||||
SpellStaminaCost = config.Bind(spell, "Stamina Cost", 20f,
|
||||
new ConfigDescription("Stamina spent per cast.", new AcceptableValueRange<float>(0f, 100f)));
|
||||
|
|
|
|||
460
JotunnModStub/Skadi/SkadiGolem.cs
Normal file
460
JotunnModStub/Skadi/SkadiGolem.cs
Normal file
|
|
@ -0,0 +1,460 @@
|
|||
using System.Collections.Generic;
|
||||
using HarmonyLib;
|
||||
using Jotunn.Configs;
|
||||
using Jotunn.Entities;
|
||||
using Jotunn.Managers;
|
||||
using UnityEngine;
|
||||
|
||||
namespace RacesOfValheim
|
||||
{
|
||||
/// <summary>
|
||||
/// The Skadi station: crystal golems, cut at a stonecutter and bound to it.
|
||||
///
|
||||
/// Eighth of the per-race item-progression chains, and the odd one out in two ways that decide
|
||||
/// everything else in this file.
|
||||
///
|
||||
/// FIRST, the station is not ours. Every other chain builds its own bench - a trough, a bone pile,
|
||||
/// a composter - and can therefore hang a MonoBehaviour on it, count its own garrison from it, and
|
||||
/// mark its thralls when it falls. The stonecutter is vanilla's, and nothing here modifies it: the
|
||||
/// golem carries the stonecutter's position in its own ZDO and asks the world whether one still
|
||||
/// stands there. That is why this chain does not use RaisedThrall, which is otherwise exactly the
|
||||
/// right component - RaisedThrall's wither depends on the station registering itself, and a vanilla
|
||||
/// piece never will.
|
||||
///
|
||||
/// SECOND, a golem is not a follower. RaisedThrall's whole vocabulary - follow me, stand down, call
|
||||
/// to arms - is wrong for something that may not leave a twenty metre circle. There is deliberately
|
||||
/// no Tameable on it either: it is tame, so it will never turn on anyone, but it cannot be named,
|
||||
/// ordered, or walked away with. It guards the stone that shaped it, and that is all it does.
|
||||
///
|
||||
/// The three limits are the design, not decoration:
|
||||
/// never further than 20 m from its stonecutter (the vanilla station build range)
|
||||
/// two per stonecutter
|
||||
/// ten per square mile
|
||||
/// The first is enforced on the golem (SkadiGolemGuard), the other two at the moment of building,
|
||||
/// through PieceDensityLimit's single Player.PlacePiece prefix - refusing later would spend a
|
||||
/// dragon tear before telling anyone no.
|
||||
/// </summary>
|
||||
public static class SkadiGolem
|
||||
{
|
||||
// ─── Names ───────────────────────────────────────────────────────────
|
||||
public const string GolemName = "SkadiCrystalGolem";
|
||||
public const string SeedPieceName = "SkadiCrystalGolemSeed";
|
||||
public const string DisplayName = "Crystal Golem";
|
||||
|
||||
private const string SourceGolem = "StoneGolem";
|
||||
|
||||
/// <summary>
|
||||
/// The seed piece's model, and it is chosen for its BUILD GHOST: the golem itself only exists
|
||||
/// a frame later, so a standing stone is what the player actually aims with. Everything the
|
||||
/// ward DOES - the private area above all - is stripped off the clone below; a chain that
|
||||
/// quietly planted a ward every time you cut a golem would be a much worse bug than a wrong
|
||||
/// silhouette.
|
||||
/// </summary>
|
||||
private const string SourcePiece = "guard_stone";
|
||||
|
||||
public const string StationPrefab = "piece_stonecutter";
|
||||
|
||||
// ─── The price ───────────────────────────────────────────────────────
|
||||
// Moder needs no state check of her own to BUILD one - her drop is in the recipe - but the
|
||||
// gate asks anyway, because the recipe is not the only way an item reaches an inventory.
|
||||
public const string GolemTrophy = "TrophySGolem";
|
||||
public const string CrystalItem = "Crystal";
|
||||
public const int CrystalCost = 10;
|
||||
public const string ModerDrop = "DragonTear";
|
||||
public const int ModerProgressionState = 5;
|
||||
|
||||
// ─── The limits ──────────────────────────────────────────────────────
|
||||
|
||||
/// <summary>
|
||||
/// How far a golem may get from its stonecutter. Twenty metres because that is the
|
||||
/// stonecutter's own build range in vanilla, so the circle a golem defends is exactly the
|
||||
/// circle it could have been built in - one number, visible in game, not two that nearly
|
||||
/// agree.
|
||||
/// </summary>
|
||||
public const float LeashRange = 20f;
|
||||
|
||||
/// <summary>
|
||||
/// Past this it has stopped walking home and started failing to. A golem that has been pushed
|
||||
/// into water, or that stands on the wrong side of something it cannot path around, would
|
||||
/// otherwise sit outside its leash forever - so at half again the leash it is simply put back.
|
||||
/// It is a failsafe for a stuck pathfinder, not a movement mechanic.
|
||||
/// </summary>
|
||||
public const float HardLeashRange = 30f;
|
||||
|
||||
public const int MaxPerStation = 2;
|
||||
|
||||
// Ten per square mile. 2.59 km2, the same area the Fenrir's trough is measured in, so the two
|
||||
// stations are spaced by the same yardstick even though the numbers differ.
|
||||
public const int MaxInArea = 10;
|
||||
public const float DensityAreaKm2 = 2.59f;
|
||||
|
||||
/// <summary>
|
||||
/// How long a golem outlives the stonecutter that cut it. Shorter than the Fenrir trough's
|
||||
/// five minutes because there is nothing to rebuild: a stonecutter costs ten stone and two
|
||||
/// wood, so "put it back" is a moment's work, and a longer grace would just mean a garrison
|
||||
/// that survives being moved.
|
||||
/// </summary>
|
||||
public const float WitherSeconds = 60f;
|
||||
|
||||
/// <summary>Slack when asking "is my stonecutter still there" - a station never moves.</summary>
|
||||
public const float StationCheckRange = 2f;
|
||||
|
||||
/// <summary>
|
||||
/// Only asked this close to home, for the reason RaisedThrall's wither carries the same guard:
|
||||
/// further out the station's zone is probably not loaded, so "nothing stands there" would be a
|
||||
/// lie. A golem is leashed to 20 m anyway, so this is never the reason one survives.
|
||||
/// </summary>
|
||||
public const float HomeCheckRange = 40f;
|
||||
|
||||
// ─── Behaviour ───────────────────────────────────────────────────────
|
||||
|
||||
/// <summary>Idle wander around the stonecutter. Half the leash, so it never idles onto it.</summary>
|
||||
private const float WanderRange = 10f;
|
||||
|
||||
/// <summary>
|
||||
/// The station's m_name, read off the stonecutter prefab once at registration.
|
||||
///
|
||||
/// It is NOT the prefab name: CraftingStation.HaveBuildStationInRange compares against
|
||||
/// m_name, which is a localisation token, while Jotunn's PieceConfig.CraftingStation wants the
|
||||
/// prefab name. Both spellings are needed and they are not the same string, which is exactly
|
||||
/// the kind of thing worth reading off the game once instead of guessing at twice.
|
||||
/// </summary>
|
||||
private static string StationName = "$piece_stonecutter";
|
||||
|
||||
public static void Register()
|
||||
{
|
||||
CacheStationName();
|
||||
|
||||
if (!RegisterGolem()) return;
|
||||
RegisterSeedPiece();
|
||||
|
||||
PieceDensityLimit.RegisterGate(SeedPieceName, MayRaise);
|
||||
}
|
||||
|
||||
private static void CacheStationName()
|
||||
{
|
||||
GameObject station = PrefabManager.Cache.GetPrefab<GameObject>(StationPrefab);
|
||||
CraftingStation component = station != null ? station.GetComponent<CraftingStation>() : null;
|
||||
|
||||
if (component == null || string.IsNullOrEmpty(component.m_name))
|
||||
{
|
||||
Jotunn.Logger.LogWarning($"[Skadi] Could not read the stonecutter's station name off " +
|
||||
$"'{StationPrefab}'; falling back to '{StationName}'.");
|
||||
return;
|
||||
}
|
||||
|
||||
StationName = component.m_name;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- the golem
|
||||
|
||||
/// <summary>
|
||||
/// A vanilla stone golem, tamed, frozen over, and made incapable of the three things it must
|
||||
/// never do.
|
||||
///
|
||||
/// Health, damage and resistances stay exactly as vanilla has them. A mountain golem is a slow
|
||||
/// wall with a great deal of health, which is precisely what a defender that cannot leave its
|
||||
/// circle should be - there is nothing to retune, and nothing here does.
|
||||
///
|
||||
/// What IS written over:
|
||||
/// - it does not sleep. Vanilla golems start as rocks and wake when something comes near;
|
||||
/// a guard that has to be woken up is not a guard.
|
||||
/// - it does not target player-built anything (m_attackPlayerObjects). That is the first
|
||||
/// half of "never attacks structures"; the second half is the WearNTear guard below,
|
||||
/// because an area attack aimed at a greydwarf can still land on a wall.
|
||||
/// - it does not flee. A golem holds its ground or it dies on it.
|
||||
/// - it gives up a chase past its leash, measured from its own spawn point, which
|
||||
/// SkadiGolemGuard pins to the stonecutter. That is vanilla's own leash, used as intended
|
||||
/// rather than reimplemented.
|
||||
/// - it drops nothing. Two golems per stonecutter that could be farmed for crystals and
|
||||
/// trophies would be a mint, and the trophy is this chain's own gate item.
|
||||
/// It never attacks tamed creatures or players for free: Attack.DoMeleeAttack only lets a
|
||||
/// tamed attacker through to targets its own AI counts as enemies, which is checked in the
|
||||
/// game's code rather than assumed here.
|
||||
/// </summary>
|
||||
private static bool RegisterGolem()
|
||||
{
|
||||
GameObject prefab = PrefabManager.Instance.CreateClonedPrefab(GolemName, SourceGolem);
|
||||
if (prefab == null)
|
||||
{
|
||||
Jotunn.Logger.LogWarning($"[Skadi] Could not clone {SourceGolem}; {DisplayName} not registered.");
|
||||
return false;
|
||||
}
|
||||
|
||||
Character character = prefab.GetComponent<Character>();
|
||||
if (character != null) character.m_name = DisplayName;
|
||||
|
||||
SkadiIce.Apply(prefab);
|
||||
|
||||
BaseAI ai = prefab.GetComponent<BaseAI>();
|
||||
if (ai != null)
|
||||
{
|
||||
ai.m_randomMoveRange = WanderRange;
|
||||
ai.m_avoidWater = true;
|
||||
}
|
||||
|
||||
MonsterAI monster = prefab.GetComponent<MonsterAI>();
|
||||
if (monster != null)
|
||||
{
|
||||
monster.m_sleeping = false;
|
||||
monster.m_attackPlayerObjects = false;
|
||||
|
||||
// It notices what comes into the circle it defends, and nothing outside it. Being
|
||||
// hit still turns it around - OnDamaged sets a target whatever the alert range says -
|
||||
// which is the difference between a defender and a statue.
|
||||
monster.m_alertRange = LeashRange;
|
||||
monster.m_maxChaseDistance = LeashRange;
|
||||
monster.m_fleeIfLowHealth = 0f;
|
||||
monster.m_fleeIfNotAlerted = false;
|
||||
monster.m_fleeIfHurtWhenTargetCantBeReached = false;
|
||||
}
|
||||
|
||||
foreach (CharacterDrop drops in prefab.GetComponentsInChildren<CharacterDrop>(true))
|
||||
{
|
||||
if (drops != null) Object.DestroyImmediate(drops);
|
||||
}
|
||||
|
||||
foreach (Procreation breeding in prefab.GetComponentsInChildren<Procreation>(true))
|
||||
{
|
||||
if (breeding != null) Object.DestroyImmediate(breeding);
|
||||
}
|
||||
|
||||
// "Ten seconds unhurt, then 2% a second" - the Skeleton's sentry regeneration, which three
|
||||
// chains now share. A guard that cannot heal between raids is a guard you rebuild.
|
||||
prefab.AddComponent<SkeletonSentryBehaviour>();
|
||||
|
||||
prefab.AddComponent<SkadiGolemGuard>();
|
||||
|
||||
PrefabManager.Instance.AddPrefab(prefab);
|
||||
Jotunn.Logger.LogInfo($"[Skadi] {GolemName} from '{SourceGolem}': awake, tame, leashed, " +
|
||||
"blind to structures, drops nothing.");
|
||||
return true;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- the seed piece
|
||||
|
||||
/// <summary>
|
||||
/// The hammer entry, and the same trick SkeletonSentry uses for the same reason: the hammer
|
||||
/// builds Piece, a golem is a Character, so a piece is placed and swaps itself for one.
|
||||
/// </summary>
|
||||
private static void RegisterSeedPiece()
|
||||
{
|
||||
GameObject prefab = PrefabManager.Instance.CreateClonedPrefab(SeedPieceName, SourcePiece);
|
||||
if (prefab == null)
|
||||
{
|
||||
Jotunn.Logger.LogWarning($"[Skadi] Could not clone {SourcePiece}; {DisplayName} cannot be built.");
|
||||
return;
|
||||
}
|
||||
|
||||
// Everything the ward does goes - PrivateArea and its effect areas above all. What is
|
||||
// wanted is a placeable shell with the right outline, alive for one frame.
|
||||
foreach (MonoBehaviour behaviour in prefab.GetComponentsInChildren<MonoBehaviour>(true))
|
||||
{
|
||||
if (behaviour == null) continue;
|
||||
if (behaviour is Piece || behaviour is ZNetView || behaviour is WearNTear) continue;
|
||||
Object.DestroyImmediate(behaviour);
|
||||
}
|
||||
|
||||
AswidBloodRefinery.StripOffensive(prefab, SeedPieceName);
|
||||
SkadiIce.Apply(prefab);
|
||||
|
||||
prefab.AddComponent<SkadiGolemSeed>();
|
||||
|
||||
Piece piece = prefab.GetComponent<Piece>() ?? prefab.AddComponent<Piece>();
|
||||
piece.m_resources = new Piece.Requirement[0];
|
||||
piece.m_name = DisplayName;
|
||||
piece.m_canBeRemoved = true;
|
||||
piece.m_groundPiece = true;
|
||||
piece.m_groundOnly = true;
|
||||
piece.m_icon = BorrowIcon(CrystalItem);
|
||||
|
||||
PieceManager.Instance.AddPiece(new CustomPiece(prefab, fixReference: false, new PieceConfig
|
||||
{
|
||||
Name = DisplayName,
|
||||
Description = "Cut at the stone and woken with a tear. It will not follow you, and it " +
|
||||
"will not leave the stonecutter that shaped it.",
|
||||
PieceTable = PieceTables.Hammer,
|
||||
Category = PieceCategories.Crafting,
|
||||
// The stonecutter is the station, so vanilla itself refuses to place one anywhere its
|
||||
// golem could not then be bound - the gate below never has to be the first to say no.
|
||||
CraftingStation = CraftingStations.Stonecutter,
|
||||
Icon = BorrowIcon(CrystalItem),
|
||||
Requirements = new[]
|
||||
{
|
||||
new RequirementConfig(GolemTrophy, 1, 0, true),
|
||||
new RequirementConfig(CrystalItem, CrystalCost, 0, true),
|
||||
new RequirementConfig(ModerDrop, 1, 0, true),
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- the gate
|
||||
|
||||
/// <summary>
|
||||
/// The two caps that cannot live on the golem, asked at the moment of building.
|
||||
///
|
||||
/// Order matters: race, then boss, then the stonecutter, then its own two, so the first thing
|
||||
/// a player is told is the thing they can actually do something about.
|
||||
///
|
||||
/// HONEST LIMIT, inherited from PieceDensityLimit and worth repeating: the counts are over
|
||||
/// ZDOs, which on a remote client are only the ZDOs the server has sent. On the host they are
|
||||
/// exact. Where a count cannot be taken at all the placement is allowed - refusing on no
|
||||
/// information is worse than a cap that occasionally misses.
|
||||
/// </summary>
|
||||
public static bool MayRaise(Player player, Vector3 position)
|
||||
{
|
||||
if (player == null) return true;
|
||||
|
||||
if (!SkadiRace.IsLocalSkadi())
|
||||
{
|
||||
player.Message(MessageHud.MessageType.Center, "The stone does not answer to you.");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (BossProgressionManager.GetCurrentProgressionState() < ModerProgressionState)
|
||||
{
|
||||
player.Message(MessageHud.MessageType.Center,
|
||||
"The tear is cold. Nothing wakes in the stone until the mountain's queen has fallen.");
|
||||
return false;
|
||||
}
|
||||
|
||||
CraftingStation station = FindStonecutter(position);
|
||||
if (station == null)
|
||||
{
|
||||
player.Message(MessageHud.MessageType.Center, "It needs a stonecutter to be cut at.");
|
||||
return false;
|
||||
}
|
||||
|
||||
int bound = CountBoundTo(station.transform.position);
|
||||
if (bound >= MaxPerStation)
|
||||
{
|
||||
player.Message(MessageHud.MessageType.Center,
|
||||
$"That stonecutter already holds {bound}. It will not hold more.");
|
||||
return false;
|
||||
}
|
||||
|
||||
int nearby = PieceDensityLimit.Count(GolemName, position, PieceDensityLimit.RadiusForArea(DensityAreaKm2));
|
||||
if (nearby >= MaxInArea)
|
||||
{
|
||||
player.Message(MessageHud.MessageType.Center,
|
||||
$"There are already {nearby} of these within a day's walk. The stone is spent.");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The stonecutter that owns a point, by the station's OWN build range rather than by a number
|
||||
/// of ours - so the circle a golem may be cut in and the circle it may stand in are the same
|
||||
/// circle, and stay the same if a game update retunes the station.
|
||||
/// </summary>
|
||||
public static CraftingStation FindStonecutter(Vector3 position)
|
||||
{
|
||||
return CraftingStation.HaveBuildStationInRange(StationName, position);
|
||||
}
|
||||
|
||||
/// <summary>True if a stonecutter still stands at that exact point.</summary>
|
||||
public static bool StonecutterStandsAt(Vector3 position)
|
||||
{
|
||||
return CraftingStation.FindClosestStationInRange(StationName, position, StationCheckRange) != null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// How many golems already answer to the stonecutter at that point, counted over ZDOs and not
|
||||
/// over loaded creatures.
|
||||
///
|
||||
/// That distinction is the whole cap: a golem in an unloaded zone is still a golem, and
|
||||
/// counting only what is loaded would make walking away and coming back the way to hold six.
|
||||
/// Dead ones are gone from the world entirely, so a slot frees itself with no bookkeeping.
|
||||
/// </summary>
|
||||
public static int CountBoundTo(Vector3 station)
|
||||
{
|
||||
List<ZDO> zdos = new List<ZDO>();
|
||||
if (!PieceDensityLimit.Gather(GolemName, zdos)) return 0;
|
||||
|
||||
int count = 0;
|
||||
foreach (ZDO zdo in zdos)
|
||||
{
|
||||
if (zdo == null) continue;
|
||||
|
||||
// A generous epsilon: a station never moves, so this only has to survive float
|
||||
// round-tripping through the ZDO.
|
||||
Vector3 anchor = zdo.GetVec3(SkadiGolemGuard.KeyAnchor, Vector3.zero);
|
||||
if (anchor != Vector3.zero && Vector3.SqrMagnitude(anchor - station) < 0.25f) count++;
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- known pieces
|
||||
|
||||
/// <summary>
|
||||
/// Learnt by being Skadi, and not by having killed Moder.
|
||||
///
|
||||
/// Deliberate: the entry shows up greyed out with its price on it, which is how every vanilla
|
||||
/// recipe tells you what to go and get. Gating the entry itself on the boss would hide it
|
||||
/// until a relog anyway - OnSpawned is the only moment this is asked - so the boss check lives
|
||||
/// where it can be asked every time instead, in MayRaise.
|
||||
/// </summary>
|
||||
public static void EnsureKnown(Player player)
|
||||
{
|
||||
if (player == null || !SkadiRace.IsLocalSkadi()) return;
|
||||
|
||||
GameObject prefab = PrefabManager.Instance.GetPrefab(SeedPieceName);
|
||||
Piece piece = prefab != null ? prefab.GetComponent<Piece>() : null;
|
||||
if (piece == null) return;
|
||||
|
||||
Traverse traverse = Traverse.Create(player);
|
||||
traverse.Method("AddKnownPiece", piece).GetValue();
|
||||
traverse.Method("UpdateAvailablePiecesList").GetValue();
|
||||
}
|
||||
|
||||
private static Sprite BorrowIcon(string prefabName)
|
||||
{
|
||||
ItemDrop drop = PrefabManager.Cache.GetPrefab<ItemDrop>(prefabName);
|
||||
Sprite[] icons = drop != null && drop.m_itemData != null && drop.m_itemData.m_shared != null
|
||||
? drop.m_itemData.m_shared.m_icons
|
||||
: null;
|
||||
if (icons != null && icons.Length > 0 && icons[0] != null) return icons[0];
|
||||
|
||||
Jotunn.Logger.LogWarning($"[Skadi] Could not borrow the icon from '{prefabName}'.");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
[HarmonyPatch(typeof(Player), "OnSpawned")]
|
||||
public static class SkadiGolemKnownPatch
|
||||
{
|
||||
public static void Postfix(Player __instance)
|
||||
{
|
||||
if (__instance != Player.m_localPlayer) return;
|
||||
SkadiGolem.EnsureKnown(__instance);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The second half of "it never attacks structures".
|
||||
///
|
||||
/// m_attackPlayerObjects stops a golem CHOOSING a wall as a target; it does not stop one landing a
|
||||
/// swing on the wall behind a greydwarf, because Attack.DoMeleeAttack has no tamed check on the
|
||||
/// destructible path at all - only on the character one. Read off the game's own code rather than
|
||||
/// assumed, and it is why this patch exists instead of one field being trusted to do both jobs.
|
||||
///
|
||||
/// The signature is spelled out and bound positionally for the reason PieceDensityLimitPatch
|
||||
/// carries in its own comment: Damage returns VOID, so a prefix returning false is the whole
|
||||
/// mechanism, and asking for a __result on a void method throws at patch time and takes the rest
|
||||
/// of the mod's patches down with it.
|
||||
/// </summary>
|
||||
[HarmonyPatch(typeof(WearNTear), "Damage", new[] { typeof(HitData) })]
|
||||
public static class SkadiGolemStructureGuardPatch
|
||||
{
|
||||
public static bool Prefix(HitData __0)
|
||||
{
|
||||
if (__0 == null) return true;
|
||||
|
||||
Character attacker = __0.GetAttacker();
|
||||
return attacker == null || attacker.GetComponent<SkadiGolemGuard>() == null;
|
||||
}
|
||||
}
|
||||
}
|
||||
302
JotunnModStub/Skadi/SkadiGolemBehaviour.cs
Normal file
302
JotunnModStub/Skadi/SkadiGolemBehaviour.cs
Normal file
|
|
@ -0,0 +1,302 @@
|
|||
using System;
|
||||
using HarmonyLib;
|
||||
using UnityEngine;
|
||||
|
||||
namespace RacesOfValheim
|
||||
{
|
||||
/// <summary>
|
||||
/// One crystal golem: tame, bound to a stonecutter, and unable to get more than its leash away
|
||||
/// from it.
|
||||
///
|
||||
/// Same shape as RaisedThrall - an anchor in the creature's own ZDO, a leash pinned to it, a
|
||||
/// wither clock that starts when the station is gone - and deliberately NOT that class. Two
|
||||
/// differences make it a copy rather than a reuse, and both are in SkadiGolem's own comment: the
|
||||
/// station is vanilla's and cannot register itself, and a golem takes no orders, so the follow,
|
||||
/// stand-down and call-to-arms half of RaisedThrall is not merely unused here but wrong.
|
||||
///
|
||||
/// The leash is three layers, weakest first, because each one covers the case the one before it
|
||||
/// cannot:
|
||||
/// - vanilla's own chase limit (m_maxChaseDistance, measured from m_spawnPoint, which is pinned
|
||||
/// to the stonecutter below) makes it GIVE UP on anything it would have to leave home for;
|
||||
/// - the patrol point, re-pinned every tick, is what brings it back and what keeps it wandering
|
||||
/// around the station rather than drifting after it has been pushed or knocked back;
|
||||
/// - and past half again the leash it is simply put back, because at that distance it is not
|
||||
/// walking home slowly, it is failing to walk home at all.
|
||||
/// </summary>
|
||||
public class SkadiGolemGuard : MonoBehaviour
|
||||
{
|
||||
public const string KeyAnchor = "RoV_golemAnchor";
|
||||
public const string KeyOrphanAt = "RoV_golemOrphanAt";
|
||||
|
||||
/// <summary>
|
||||
/// One second, and not the two RaisedThrall uses. Vanilla will not drop a target it can still
|
||||
/// SEE, whatever m_maxChaseDistance says - read off MonsterAI.UpdateTarget, where the give-up
|
||||
/// test also wants a second of having lost sight of it - so this tick is what actually holds
|
||||
/// the leash, and how far past twenty metres a golem gets is how far it walks between two of
|
||||
/// them. A stone golem is slow; at one second that is a stride.
|
||||
/// </summary>
|
||||
private const float TickSeconds = 1f;
|
||||
|
||||
// SetPatrolPoint(Vector3) is private - only the parameterless overload, which uses the
|
||||
// creature's current position, is public. Resolved once here rather than per call, exactly as
|
||||
// RaisedThrall does it.
|
||||
private static readonly System.Reflection.MethodInfo SetPatrolPointMethod =
|
||||
AccessTools.Method(typeof(BaseAI), "SetPatrolPoint", new[] { typeof(Vector3) });
|
||||
|
||||
// m_spawnPoint is protected, and it is the point vanilla measures m_maxChaseDistance from -
|
||||
// read off MonsterAI.UpdateTarget rather than assumed, because "chase distance" could just as
|
||||
// easily have meant distance from the target.
|
||||
private static readonly System.Reflection.FieldInfo SpawnPointField =
|
||||
AccessTools.Field(typeof(BaseAI), "m_spawnPoint");
|
||||
|
||||
private Character m_character;
|
||||
private BaseAI m_ai;
|
||||
private MonsterAI m_monsterAI;
|
||||
private ZNetView m_nview;
|
||||
private Rigidbody m_body;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
m_character = GetComponent<Character>();
|
||||
m_ai = GetComponent<BaseAI>();
|
||||
m_monsterAI = GetComponent<MonsterAI>();
|
||||
m_nview = GetComponent<ZNetView>();
|
||||
m_body = GetComponent<Rigidbody>();
|
||||
|
||||
InvokeRepeating("Tick", TickSeconds, TickSeconds);
|
||||
}
|
||||
|
||||
/// <summary>Where the stonecutter that cut this one stands, or null if it was cut by none.</summary>
|
||||
public Vector3? Anchor
|
||||
{
|
||||
get
|
||||
{
|
||||
if (m_nview == null || !m_nview.IsValid()) return null;
|
||||
|
||||
Vector3 anchor = m_nview.GetZDO().GetVec3(KeyAnchor, Vector3.zero);
|
||||
return anchor == Vector3.zero ? (Vector3?)null : anchor;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called once, by the seed piece that placed it. Tames it, marks whose stonecutter it is, and
|
||||
/// sends it home - all three, so nothing else has to remember to do any of them.
|
||||
/// </summary>
|
||||
public void Bind(Vector3 anchor)
|
||||
{
|
||||
if (m_nview == null || !m_nview.IsValid()) return;
|
||||
|
||||
m_nview.GetZDO().Set(KeyAnchor, anchor);
|
||||
|
||||
if (m_monsterAI != null) m_monsterAI.MakeTame();
|
||||
if (m_character != null) m_character.SetTamed(true);
|
||||
|
||||
GoHome();
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- the tick
|
||||
|
||||
private void Tick()
|
||||
{
|
||||
if (m_nview == null || !m_nview.IsValid() || !m_nview.IsOwner()) return;
|
||||
if (m_character == null || m_character.IsDead()) return;
|
||||
|
||||
if (TickWither()) return;
|
||||
|
||||
Vector3? anchor = Anchor;
|
||||
if (anchor == null) return;
|
||||
|
||||
float distance = Vector3.Distance(transform.position, anchor.Value);
|
||||
|
||||
if (distance > SkadiGolem.LeashRange)
|
||||
{
|
||||
// Whatever it was going after is outside the circle it defends, so it stops going
|
||||
// after it. Vanilla would drop the target itself a second or so later through
|
||||
// m_maxChaseDistance; doing it here as well means the leash does not depend on that
|
||||
// one field surviving a game update.
|
||||
ClearTarget();
|
||||
}
|
||||
|
||||
if (distance > SkadiGolem.HardLeashRange) SnapHome(anchor.Value);
|
||||
|
||||
// Every tick, and not only when it has strayed: this is also what pins m_spawnPoint after
|
||||
// a zone reload, where Bind is never called again.
|
||||
GoHome();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Starts the clock when the stonecutter is gone, and stops the golem when it runs out.
|
||||
/// Returns true once it has done so, so the caller stops bothering with it.
|
||||
///
|
||||
/// Without some form of this a stonecutter is a duplication exploit: cut two golems, take the
|
||||
/// stonecutter down, put it up somewhere else, and keep both from every round.
|
||||
/// </summary>
|
||||
private bool TickWither()
|
||||
{
|
||||
Vector3? anchor = Anchor;
|
||||
if (anchor == null || ZNet.instance == null) return false;
|
||||
|
||||
long stamp = m_nview.GetZDO().GetLong(KeyOrphanAt, 0L);
|
||||
|
||||
if (stamp == 0L)
|
||||
{
|
||||
// Only asked from close to home - see SkadiGolem.HomeCheckRange. Being leashed to
|
||||
// twenty metres, a golem is essentially always close enough, so this guard is about
|
||||
// the moment after a zone loads rather than about distance.
|
||||
if (Vector3.SqrMagnitude(transform.position - anchor.Value) >
|
||||
SkadiGolem.HomeCheckRange * SkadiGolem.HomeCheckRange) return false;
|
||||
|
||||
if (SkadiGolem.StonecutterStandsAt(anchor.Value)) return false;
|
||||
|
||||
MarkOrphaned();
|
||||
return false;
|
||||
}
|
||||
|
||||
// Put back in time, on the same spot: the clock is cleared and the golem lives. It opens
|
||||
// no exploit - a stonecutter on the same spot owns these golems by anchor anyway.
|
||||
if (SkadiGolem.StonecutterStandsAt(anchor.Value))
|
||||
{
|
||||
m_nview.GetZDO().Set(KeyOrphanAt, 0L);
|
||||
return false;
|
||||
}
|
||||
|
||||
double elapsed = (ZNet.instance.GetTime() - new DateTime(stamp)).TotalSeconds;
|
||||
if (elapsed < SkadiGolem.WitherSeconds) return false;
|
||||
|
||||
Crumble();
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>Starts the wither clock, once. Idempotent, so it cannot be restarted and keep an
|
||||
/// orphan alive forever.</summary>
|
||||
private void MarkOrphaned()
|
||||
{
|
||||
if (m_nview == null || !m_nview.IsValid() || ZNet.instance == null) return;
|
||||
if (m_nview.GetZDO().GetLong(KeyOrphanAt, 0L) != 0L) return;
|
||||
|
||||
m_nview.ClaimOwnership();
|
||||
m_nview.GetZDO().Set(KeyOrphanAt, ZNet.instance.GetTime().Ticks);
|
||||
|
||||
if (Player.m_localPlayer != null &&
|
||||
Vector3.Distance(Player.m_localPlayer.transform.position, transform.position) < 30f)
|
||||
{
|
||||
Player.m_localPlayer.Message(MessageHud.MessageType.Center,
|
||||
"The stonecutter is gone. What it cut will not outlast it by long.");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Pins the patrol point - and the spawn point vanilla measures its own chase limit from -
|
||||
/// back onto the stonecutter. Cheap enough to call on a timer, and calling it repeatedly is
|
||||
/// what stops a golem drifting after it has been pushed or knocked back.
|
||||
/// </summary>
|
||||
private void GoHome()
|
||||
{
|
||||
Vector3? anchor = Anchor;
|
||||
if (anchor == null || m_ai == null) return;
|
||||
|
||||
if (SpawnPointField != null) SpawnPointField.SetValue(m_ai, anchor.Value);
|
||||
|
||||
if (SetPatrolPointMethod != null)
|
||||
{
|
||||
SetPatrolPointMethod.Invoke(m_ai, new object[] { anchor.Value });
|
||||
}
|
||||
else
|
||||
{
|
||||
// Fall back to writing the two fields the private method writes.
|
||||
Traverse traverse = Traverse.Create(m_ai);
|
||||
traverse.Field("m_patrolPoint").SetValue(anchor.Value);
|
||||
traverse.Field("m_patrol").SetValue(true);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Forgets whatever it was going after, creature or otherwise.</summary>
|
||||
private void ClearTarget()
|
||||
{
|
||||
if (m_monsterAI == null) return;
|
||||
|
||||
Traverse traverse = Traverse.Create(m_monsterAI);
|
||||
traverse.Field("m_targetCreature").SetValue(null);
|
||||
traverse.Field("m_targetStatic").SetValue(null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The failsafe, and only that. A golem that is this far out has not wandered - it has been
|
||||
/// pushed somewhere it cannot path back from, and the alternative to putting it back is one
|
||||
/// that stands in a lake until its stonecutter falls.
|
||||
/// </summary>
|
||||
private void SnapHome(Vector3 anchor)
|
||||
{
|
||||
Vector2 offset = UnityEngine.Random.insideUnitCircle * 3f;
|
||||
Vector3 destination = anchor + new Vector3(offset.x, 0.5f, offset.y);
|
||||
|
||||
transform.position = destination;
|
||||
if (m_body != null) m_body.linearVelocity = Vector3.zero;
|
||||
|
||||
ClearTarget();
|
||||
|
||||
Jotunn.Logger.LogWarning($"[Skadi] A golem was {SkadiGolem.HardLeashRange:0} m or more from its " +
|
||||
"stonecutter and could not walk back; it was put back.");
|
||||
}
|
||||
|
||||
private void Crumble()
|
||||
{
|
||||
if (m_character == null || m_character.IsDead()) return;
|
||||
|
||||
HitData hit = new HitData();
|
||||
hit.m_damage.m_damage = 1E+10f;
|
||||
hit.m_hitType = HitData.HitType.Undefined;
|
||||
m_character.ApplyDamage(hit, true, false);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Lives for one frame: swaps itself for the golem and goes. Owner only, so in multiplayer exactly
|
||||
/// one golem stands up rather than one per client.
|
||||
///
|
||||
/// The stonecutter is looked up again here rather than handed over by the placement gate, and that
|
||||
/// is deliberate: both call SkadiGolem.FindStonecutter with the same point, so both get the same
|
||||
/// answer, and there is no piece of state between them that can go stale or arrive out of order.
|
||||
///
|
||||
/// If the lookup comes back empty the materials are lost, and that is the honest outcome rather
|
||||
/// than an oversight: it can only happen if the stonecutter was taken down between the gate saying
|
||||
/// yes and this frame, and the alternative - a golem anchored to nothing - would wither in a
|
||||
/// minute anyway while looking like a bug.
|
||||
/// </summary>
|
||||
public class SkadiGolemSeed : MonoBehaviour
|
||||
{
|
||||
private void Start()
|
||||
{
|
||||
ZNetView nview = GetComponent<ZNetView>();
|
||||
if (nview == null || !nview.IsValid() || !nview.IsOwner()) return;
|
||||
|
||||
GameObject prefab = ZNetScene.instance != null
|
||||
? ZNetScene.instance.GetPrefab(SkadiGolem.GolemName)
|
||||
: null;
|
||||
|
||||
if (prefab == null)
|
||||
{
|
||||
Jotunn.Logger.LogWarning($"[Skadi] No '{SkadiGolem.GolemName}' in ZNetScene; nothing was cut.");
|
||||
ZNetScene.instance.Destroy(gameObject);
|
||||
return;
|
||||
}
|
||||
|
||||
CraftingStation station = SkadiGolem.FindStonecutter(transform.position);
|
||||
if (station == null)
|
||||
{
|
||||
Jotunn.Logger.LogWarning("[Skadi] No stonecutter in range at the moment of cutting; " +
|
||||
"nothing was raised.");
|
||||
ZNetScene.instance.Destroy(gameObject);
|
||||
return;
|
||||
}
|
||||
|
||||
GameObject spawned = Instantiate(prefab, transform.position, transform.rotation);
|
||||
|
||||
// Bind tames it, marks whose stonecutter it is, and sends it home - all three.
|
||||
SkadiGolemGuard guard = spawned.GetComponent<SkadiGolemGuard>();
|
||||
if (guard != null) guard.Bind(station.transform.position);
|
||||
|
||||
ZNetScene.instance.Destroy(gameObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,256 +0,0 @@
|
|||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace RacesOfValheim
|
||||
{
|
||||
/// <summary>
|
||||
/// Where Skadis Nokkel takes you: a troll cave that already exists in the world, the same one
|
||||
/// every time, claimed the first time the staff is used.
|
||||
///
|
||||
/// THIRD AND FINAL SHAPE, and it is by far the smallest. What used to be here - instantiating a
|
||||
/// cave shell, learning where its interior was, emptying it of trolls, standing three benches up
|
||||
/// in it - is all gone. Four things that could each fail, and between them always did.
|
||||
///
|
||||
/// What makes the cave usable now is not here at all: RaceCaveBuilding lets a Skadi (and a Trol)
|
||||
/// build inside ANY troll cave, by lifting the one restriction that mattered. So this file has
|
||||
/// nothing left to arrange. It picks a cave, it remembers which, and it opens a door to it.
|
||||
///
|
||||
/// The three failed designs are on the record in Skadi_PortaleGhiaccio.txt sections 0c to 0g, in
|
||||
/// particular the two facts that killed them: DestroyImmediate is forbidden inside an animation
|
||||
/// event callback (and the cast runs in one), and a location's m_position is its MOUTH rather
|
||||
/// than its inside - which is why the portal kept putting the player out on the hillside.
|
||||
/// </summary>
|
||||
public static class SkadiHollow
|
||||
{
|
||||
/// <summary>
|
||||
/// Confirmed present in a live world, along with TrollCave (interior radius 0, so no use to
|
||||
/// us), MountainCave01, MountainCave02 and Hildir_cave.
|
||||
/// </summary>
|
||||
public const string SourceLocation = "TrollCave02";
|
||||
|
||||
// ─── Which cave ───────────────────────────────────────────────────────
|
||||
//
|
||||
// "Half way out, and away from the north." Half of the world's ~10 km radius is 5000, and the
|
||||
// band is generous because a Black Forest troll cave has to actually exist in it.
|
||||
private const float ClaimRadiusMin = 3500f;
|
||||
private const float ClaimRadiusMax = 6500f;
|
||||
|
||||
/// <summary>
|
||||
/// Everything with a positive Z is thrown out, which is the whole northern half of the map.
|
||||
/// Cruder than a bearing test and that is deliberate: it cannot accidentally admit the Deep
|
||||
/// North, which is where the first design landed.
|
||||
/// </summary>
|
||||
private const float MaxNorthing = 0f;
|
||||
|
||||
/// <summary>
|
||||
/// How far from the cave counts as "at my hollow" - used only by the no-planting rule now.
|
||||
/// Wide, because the cave's origin is its mouth and the inside is some way past it.
|
||||
/// </summary>
|
||||
public const float Radius = 72f;
|
||||
|
||||
// The claim is written down rather than recomputed. It depends on where this world's troll
|
||||
// caves are and on the order the candidates come back in, so recomputing it after any change
|
||||
// to either would hand the player a different cave and orphan everything built in the old one.
|
||||
private const string CaveKey = "Skadi_HollowCave";
|
||||
private const string ReturnPointKey = "Skadi_HollowReturn";
|
||||
|
||||
private static float lastCastTime = -100000f;
|
||||
|
||||
// ─── Claiming ─────────────────────────────────────────────────────────
|
||||
|
||||
/// <summary>
|
||||
/// This player's cave, if they have claimed one. Does not allocate: it is called from the
|
||||
/// build prefix, which runs on every attempted placement.
|
||||
/// </summary>
|
||||
public static bool TryGetCave(Player player, out Vector3 cave)
|
||||
{
|
||||
cave = Vector3.zero;
|
||||
if (player == null || player.m_customData == null) return false;
|
||||
return TryReadVector(player, CaveKey, out cave);
|
||||
}
|
||||
|
||||
public static bool IsInside(Player player)
|
||||
{
|
||||
if (player == null) return false;
|
||||
if (!TryGetCave(player, out Vector3 cave)) return false;
|
||||
return (player.transform.position - cave).sqrMagnitude <= Radius * Radius;
|
||||
}
|
||||
|
||||
private static bool TryClaimCave(Player player, out Vector3 cave)
|
||||
{
|
||||
if (TryGetCave(player, out cave)) return true;
|
||||
|
||||
List<Vector3> candidates = FindCandidateCaves();
|
||||
if (candidates.Count == 0)
|
||||
{
|
||||
Jotunn.Logger.LogWarning($"[Skadi] No '{SourceLocation}' found in the Black Forest between " +
|
||||
$"{ClaimRadiusMin:0} m and {ClaimRadiusMax:0} m of the centre, south of the equator. " +
|
||||
"The hollow cannot be claimed in this world.");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Sorted before indexing, because GetLocationList() makes no promise about order and an
|
||||
// unstable order would mean an unstable claim on the very first cast.
|
||||
candidates.Sort((a, b) => a.x != b.x ? a.x.CompareTo(b.x) : a.z.CompareTo(b.z));
|
||||
|
||||
cave = candidates[(int)(HashOf(player) % (uint)candidates.Count)];
|
||||
player.m_customData[CaveKey] = FormatVector(cave);
|
||||
|
||||
Jotunn.Logger.LogInfo($"[Skadi] Hollow claimed for '{player.GetPlayerName()}': {SourceLocation} at {cave} " +
|
||||
$"({BiomeAt(cave)}, {new Vector2(cave.x, cave.z).magnitude:0} m from the centre) " +
|
||||
$"- chosen from {candidates.Count} candidates.");
|
||||
return true;
|
||||
}
|
||||
|
||||
private static List<Vector3> FindCandidateCaves()
|
||||
{
|
||||
List<Vector3> found = new List<Vector3>();
|
||||
if (ZoneSystem.instance == null) return found;
|
||||
|
||||
foreach (ZoneSystem.LocationInstance instance in ZoneSystem.instance.GetLocationList())
|
||||
{
|
||||
if (instance.m_location == null) continue;
|
||||
if (instance.m_location.m_prefabName != SourceLocation) continue;
|
||||
|
||||
Vector3 position = instance.m_position;
|
||||
if (position.z > MaxNorthing) continue;
|
||||
|
||||
float distance = new Vector2(position.x, position.z).magnitude;
|
||||
if (distance < ClaimRadiusMin || distance > ClaimRadiusMax) continue;
|
||||
|
||||
if (BiomeAt(position) != Heightmap.Biome.BlackForest) continue;
|
||||
|
||||
found.Add(position);
|
||||
}
|
||||
return found;
|
||||
}
|
||||
|
||||
private static Heightmap.Biome BiomeAt(Vector3 point)
|
||||
{
|
||||
if (WorldGenerator.instance == null) return Heightmap.Biome.None;
|
||||
return WorldGenerator.instance.GetBiome(new Vector3(point.x, 0f, point.z));
|
||||
}
|
||||
|
||||
private static uint HashOf(Player player)
|
||||
{
|
||||
long id = player != null ? player.GetPlayerID() : 0L;
|
||||
if (id == 0L)
|
||||
{
|
||||
string name = player != null ? player.GetPlayerName() : null;
|
||||
id = string.IsNullOrEmpty(name) ? 1L : name.GetStableHashCode();
|
||||
}
|
||||
// Knuth's multiplicative hash, so two ids one apart do not pick neighbouring caves.
|
||||
return (uint)(id ^ (id >> 32)) * 2654435761u;
|
||||
}
|
||||
|
||||
// ─── The cast ─────────────────────────────────────────────────────────
|
||||
|
||||
/// <summary>
|
||||
/// What Skadis Nokkel does. Outside, it opens the pair; inside, it takes the player straight
|
||||
/// back out. The cooldown applies to going IN only - stepping in and changing your mind must
|
||||
/// not lock you in a cave for two minutes.
|
||||
///
|
||||
/// The far end stands at the cave's mouth, and the player walks in from there. That is not a
|
||||
/// compromise any more: since building works in the cave itself, there is nothing waiting
|
||||
/// inside that has to be lined up with, so the one point we can name honestly is the right
|
||||
/// one to use.
|
||||
/// </summary>
|
||||
public static void Cast(Player player)
|
||||
{
|
||||
if (player == null || player != Player.m_localPlayer) return;
|
||||
|
||||
if (IsInside(player))
|
||||
{
|
||||
Leave(player);
|
||||
return;
|
||||
}
|
||||
|
||||
float cooldown = SkadiConfig.HollowCooldown.Value;
|
||||
float waited = Time.time - lastCastTime;
|
||||
if (waited < cooldown)
|
||||
{
|
||||
int remaining = Mathf.CeilToInt(cooldown - waited);
|
||||
player.Message(MessageHud.MessageType.Center, $"The frost has not gathered again ({remaining}s).");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!TryClaimCave(player, out Vector3 cave))
|
||||
{
|
||||
player.Message(MessageHud.MessageType.Center, "No hollow answers you.");
|
||||
return;
|
||||
}
|
||||
|
||||
lastCastTime = Time.time;
|
||||
SkadiRace.ApplyCooldownIcon(SkadiRace.HOLLOW_COOLDOWN_SE, SkadiConfig.HollowCooldown.Value);
|
||||
|
||||
// Remembered across a logout, so casting from inside always has somewhere to put them.
|
||||
player.m_customData[ReturnPointKey] = FormatVector(player.transform.position);
|
||||
|
||||
Vector3 castPoint = player.transform.position
|
||||
+ player.transform.forward * SkadiConfig.HollowPortalSpawnDistance.Value;
|
||||
|
||||
SkadiHollowPortal.Open(castPoint, player.transform.rotation,
|
||||
cave + Vector3.up * SkadiConfig.HollowEntryHeight.Value);
|
||||
}
|
||||
|
||||
private static void Leave(Player player)
|
||||
{
|
||||
player.TeleportTo(ReturnPointFor(player), player.transform.rotation, true);
|
||||
SkadiHollowPortal.CloseSoon();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called by the portal when the player walks through. Going in changes nothing - the pair
|
||||
/// stands as long as they are inside. Coming out starts the collapse.
|
||||
/// </summary>
|
||||
public static void OnTraversed(bool intoHollow)
|
||||
{
|
||||
if (!intoHollow) SkadiHollowPortal.CloseSoon();
|
||||
}
|
||||
|
||||
private static Vector3 ReturnPointFor(Player player)
|
||||
{
|
||||
if (TryReadVector(player, ReturnPointKey, out Vector3 stored)
|
||||
&& TryGetCave(player, out Vector3 cave)
|
||||
&& (stored - cave).sqrMagnitude > Radius * Radius) // a point inside would strand them
|
||||
{
|
||||
return stored;
|
||||
}
|
||||
|
||||
// Same fallback the Trenta portal uses for its home end, and for the same reason: the
|
||||
// respawn point is the one place the game itself considers always valid.
|
||||
PlayerProfile profile = Game.instance != null ? Game.instance.GetPlayerProfile() : null;
|
||||
if (profile != null)
|
||||
{
|
||||
return profile.HaveCustomSpawnPoint() ? profile.GetCustomSpawnPoint() : PlayerProfile.m_originalSpawnPoint;
|
||||
}
|
||||
return PlayerProfile.m_originalSpawnPoint;
|
||||
}
|
||||
|
||||
// ─── customData helpers ───────────────────────────────────────────────
|
||||
|
||||
private static string FormatVector(Vector3 v)
|
||||
{
|
||||
return $"{v.x:R};{v.y:R};{v.z:R}";
|
||||
}
|
||||
|
||||
private static bool TryReadVector(Player player, string key, out Vector3 value)
|
||||
{
|
||||
value = Vector3.zero;
|
||||
if (player == null || player.m_customData == null) return false;
|
||||
if (!player.m_customData.TryGetValue(key, out string stored) || string.IsNullOrEmpty(stored)) return false;
|
||||
|
||||
string[] parts = stored.Split(';');
|
||||
if (parts.Length != 3) return false;
|
||||
|
||||
System.Globalization.CultureInfo invariant = System.Globalization.CultureInfo.InvariantCulture;
|
||||
const System.Globalization.NumberStyles style = System.Globalization.NumberStyles.Float;
|
||||
if (!float.TryParse(parts[0], style, invariant, out float x)) return false;
|
||||
if (!float.TryParse(parts[1], style, invariant, out float y)) return false;
|
||||
if (!float.TryParse(parts[2], style, invariant, out float z)) return false;
|
||||
|
||||
value = new Vector3(x, y, z);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,234 +0,0 @@
|
|||
using System.Collections;
|
||||
using Jotunn.Managers;
|
||||
using UnityEngine;
|
||||
|
||||
namespace RacesOfValheim
|
||||
{
|
||||
/// <summary>
|
||||
/// One end of the pair of portals Skadis Nokkel opens. Deliberately a copy of
|
||||
/// TrentaPortalLink rather than a shared abstraction: the two diverge on colour, on who is
|
||||
/// allowed through, and above all on when they close (the Trenta pair dies on a timer, this
|
||||
/// one waits for the player to come back out), and three differences in a forty-line class is
|
||||
/// cheaper duplicated than parameterised.
|
||||
///
|
||||
/// Everything the Trenta version earned is kept: a plain GameObject with no ZNetView, so it is
|
||||
/// unregistered and purely local - which is most of "only the player can go in", since remote
|
||||
/// clients never learn the thing exists - plus its own trigger, its own teleport call, and the
|
||||
/// same guard against the same-frame ping-pong.
|
||||
/// </summary>
|
||||
public class SkadiHollowPortalLink : MonoBehaviour
|
||||
{
|
||||
public SkadiHollowPortalLink Other;
|
||||
|
||||
/// <summary>True on the end that stands inside the hollow.</summary>
|
||||
public bool IsHollowSide;
|
||||
|
||||
// Without this, a player who arrives is still standing in the destination's own trigger and
|
||||
// gets bounced straight back the way they came, forever.
|
||||
private float reentryBlockedUntil = -1f;
|
||||
|
||||
private void OnTriggerEnter(Collider other)
|
||||
{
|
||||
if (Other == null || Time.time < reentryBlockedUntil) return;
|
||||
|
||||
Player player = other.GetComponentInParent<Player>();
|
||||
if (player == null) return;
|
||||
|
||||
// The requirement spelled out, even though the portal being local already means no
|
||||
// other player can reach this line: only the owner walks through.
|
||||
if (player != Player.m_localPlayer) return;
|
||||
|
||||
Vector3 destination = Other.transform.position + Other.transform.forward * 1.5f;
|
||||
player.TeleportTo(destination, Other.transform.rotation, true);
|
||||
|
||||
Other.reentryBlockedUntil = Time.time + 1.5f;
|
||||
|
||||
// Going in leaves the pair standing; coming out starts the collapse.
|
||||
SkadiHollow.OnTraversed(intoHollow: !IsHollowSide);
|
||||
}
|
||||
}
|
||||
|
||||
public static class SkadiHollowPortal
|
||||
{
|
||||
private static Material cachedVfxMaterial;
|
||||
private static bool vfxMaterialResolved;
|
||||
|
||||
private static GameObject outsideEnd;
|
||||
private static GameObject hollowEnd;
|
||||
private static Coroutine closing;
|
||||
|
||||
public static bool IsOpen => outsideEnd != null || hollowEnd != null;
|
||||
|
||||
/// <summary>
|
||||
/// Spawns the pair: one where the Skadi is standing, one inside their hollow. Neither end
|
||||
/// has a lifetime - they stand until CloseSoon is called.
|
||||
/// </summary>
|
||||
public static void Open(Vector3 outsidePoint, Quaternion outsideRotation, Vector3 hollowPoint)
|
||||
{
|
||||
CloseNow();
|
||||
|
||||
outsideEnd = SpawnEnd(outsidePoint, outsideRotation, isHollowSide: false);
|
||||
hollowEnd = SpawnEnd(hollowPoint, Quaternion.identity, isHollowSide: true);
|
||||
|
||||
SkadiHollowPortalLink outsideLink = outsideEnd.GetComponent<SkadiHollowPortalLink>();
|
||||
SkadiHollowPortalLink hollowLink = hollowEnd.GetComponent<SkadiHollowPortalLink>();
|
||||
outsideLink.Other = hollowLink;
|
||||
hollowLink.Other = outsideLink;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Takes both ends down after the configured grace period. Called when the player leaves the
|
||||
/// hollow - by walking out or by casting from inside - which is the only thing that closes
|
||||
/// this pair.
|
||||
/// </summary>
|
||||
public static void CloseSoon()
|
||||
{
|
||||
if (!IsOpen || closing != null) return;
|
||||
if (SkadiRace.Instance == null) { CloseNow(); return; }
|
||||
|
||||
closing = SkadiRace.Instance.StartCoroutine(
|
||||
CloseAfter(SkadiConfig.HollowPortalCloseDelay.Value));
|
||||
}
|
||||
|
||||
/// <summary>No grace period, no animation. For reopening, and for shutting down.</summary>
|
||||
public static void CloseNow()
|
||||
{
|
||||
if (closing != null && SkadiRace.Instance != null)
|
||||
{
|
||||
SkadiRace.Instance.StopCoroutine(closing);
|
||||
}
|
||||
closing = null;
|
||||
|
||||
if (outsideEnd != null) Object.Destroy(outsideEnd);
|
||||
if (hollowEnd != null) Object.Destroy(hollowEnd);
|
||||
outsideEnd = null;
|
||||
hollowEnd = null;
|
||||
}
|
||||
|
||||
private static GameObject SpawnEnd(Vector3 position, Quaternion rotation, bool isHollowSide)
|
||||
{
|
||||
GameObject portal = new GameObject(isHollowSide ? "SkadiHollowPortal_In" : "SkadiHollowPortal_Out");
|
||||
portal.transform.position = position;
|
||||
portal.transform.rotation = rotation;
|
||||
|
||||
CapsuleCollider trigger = portal.AddComponent<CapsuleCollider>();
|
||||
trigger.isTrigger = true;
|
||||
trigger.height = 3f;
|
||||
trigger.radius = 1.2f;
|
||||
trigger.center = new Vector3(0, 1.5f, 0);
|
||||
|
||||
SkadiHollowPortalLink link = portal.AddComponent<SkadiHollowPortalLink>();
|
||||
link.IsHollowSide = isHollowSide;
|
||||
|
||||
BuildSwirlVfx(portal.transform);
|
||||
|
||||
return portal;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The swirl only, no wooden frame - same shape and same reasoning as the Trenta portal's:
|
||||
/// borrow a particle material off the real portal prefab by READING it (never instantiating
|
||||
/// it, so none of the real portal's gameplay components ever get a chance to run), then
|
||||
/// drive shape, emission and colour from here. The one change is the colour, which is
|
||||
/// Skadi's ice instead of the Trenta's toxic purple.
|
||||
/// </summary>
|
||||
private static void BuildSwirlVfx(Transform parent)
|
||||
{
|
||||
if (!vfxMaterialResolved)
|
||||
{
|
||||
vfxMaterialResolved = true;
|
||||
GameObject source = PrefabManager.Cache.GetPrefab<GameObject>("portal_wood");
|
||||
if (source != null)
|
||||
{
|
||||
ParticleSystemRenderer sourceRenderer = source.GetComponentInChildren<ParticleSystemRenderer>(true);
|
||||
if (sourceRenderer != null) cachedVfxMaterial = sourceRenderer.material;
|
||||
}
|
||||
if (cachedVfxMaterial == null)
|
||||
{
|
||||
Jotunn.Logger.LogWarning("[Skadi] Hollow portal: no particle material on 'portal_wood'; using the default particle material.");
|
||||
}
|
||||
}
|
||||
|
||||
GameObject vfx = new GameObject("Swirl");
|
||||
vfx.transform.SetParent(parent, false);
|
||||
vfx.transform.localPosition = new Vector3(0, 1.2f, 0);
|
||||
|
||||
ParticleSystem ps = vfx.AddComponent<ParticleSystem>();
|
||||
var main = ps.main;
|
||||
main.loop = true;
|
||||
main.startLifetime = 1.5f;
|
||||
main.startSpeed = 0f;
|
||||
main.startSize = new ParticleSystem.MinMaxCurve(0.15f, 0.3f);
|
||||
main.maxParticles = 200;
|
||||
main.simulationSpace = ParticleSystemSimulationSpace.Local;
|
||||
|
||||
var emission = ps.emission;
|
||||
emission.rateOverTime = 80f;
|
||||
|
||||
var shape = ps.shape;
|
||||
shape.shapeType = ParticleSystemShapeType.Circle;
|
||||
shape.radius = 1f;
|
||||
shape.radiusThickness = 0.1f; // hollow ring, not a filled disc
|
||||
|
||||
var rotationOverLifetime = ps.rotationOverLifetime;
|
||||
rotationOverLifetime.enabled = true;
|
||||
rotationOverLifetime.z = new ParticleSystem.MinMaxCurve(90f);
|
||||
|
||||
ParticleSystemRenderer renderer = ps.GetComponent<ParticleSystemRenderer>();
|
||||
if (cachedVfxMaterial != null) renderer.material = cachedVfxMaterial;
|
||||
|
||||
var colorOverLifetime = ps.colorOverLifetime;
|
||||
colorOverLifetime.enabled = true;
|
||||
Gradient grad = new Gradient();
|
||||
grad.SetKeys(
|
||||
new GradientColorKey[] { new GradientColorKey(SkadiIce.PortalSwirl, 0f), new GradientColorKey(SkadiIce.PortalSwirl, 1f) },
|
||||
new GradientAlphaKey[] { new GradientAlphaKey(0f, 0f), new GradientAlphaKey(0.9f, 0.3f), new GradientAlphaKey(0.9f, 0.7f), new GradientAlphaKey(0f, 1f) }
|
||||
);
|
||||
colorOverLifetime.color = grad;
|
||||
|
||||
ps.Play();
|
||||
}
|
||||
|
||||
private static IEnumerator CloseAfter(float seconds)
|
||||
{
|
||||
yield return new WaitForSeconds(seconds);
|
||||
|
||||
GameObject a = outsideEnd;
|
||||
GameObject b = hollowEnd;
|
||||
outsideEnd = null;
|
||||
hollowEnd = null;
|
||||
closing = null;
|
||||
|
||||
yield return Collapse(a);
|
||||
yield return Collapse(b);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Link and trigger die first, so nothing can walk through mid-collapse, then a one-second
|
||||
/// shrink stands in for a closing animation - vanilla portals are simply present or absent,
|
||||
/// so there is no real one to borrow.
|
||||
/// </summary>
|
||||
private static IEnumerator Collapse(GameObject portal)
|
||||
{
|
||||
if (portal == null) yield break;
|
||||
|
||||
SkadiHollowPortalLink link = portal.GetComponent<SkadiHollowPortalLink>();
|
||||
if (link != null) Object.Destroy(link);
|
||||
|
||||
CapsuleCollider trigger = portal.GetComponent<CapsuleCollider>();
|
||||
if (trigger != null) Object.Destroy(trigger);
|
||||
|
||||
float t = 0f;
|
||||
Vector3 startScale = portal.transform.localScale;
|
||||
while (t < 1f)
|
||||
{
|
||||
if (portal == null) yield break;
|
||||
t += Time.deltaTime;
|
||||
portal.transform.localScale = Vector3.Lerp(startScale, Vector3.zero, t);
|
||||
yield return null;
|
||||
}
|
||||
|
||||
if (portal != null) Object.Destroy(portal);
|
||||
}
|
||||
}
|
||||
}
|
||||
55
JotunnModStub/Skadi/SkadiIce.cs
Normal file
55
JotunnModStub/Skadi/SkadiIce.cs
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
using UnityEngine;
|
||||
|
||||
namespace RacesOfValheim
|
||||
{
|
||||
/// <summary>
|
||||
/// The one ice palette the whole Skadi chain shares. Taken from the Fader recolour in
|
||||
/// SkadiRace.ExecuteTransformation rather than picked fresh, so the reagent and the crystal golem
|
||||
/// are the same ice as the Skeleton Dragon the race turns into at tier 8.
|
||||
///
|
||||
/// It lived in SkadiNokkel.cs until that staff was removed; it is its own file now because the
|
||||
/// two things still using it have nothing else to do with each other.
|
||||
/// </summary>
|
||||
public static class SkadiIce
|
||||
{
|
||||
public static readonly Color Albedo = new Color(0.6f, 0.8f, 1f, 1f);
|
||||
public static readonly Color Emission = new Color(0f, 0.5f, 1f, 1f);
|
||||
|
||||
/// <summary>
|
||||
/// Multiplies the ice tint over whatever the base texture already carries instead of
|
||||
/// overwriting it, so the model keeps its detail and reads as frozen bone rather than as a
|
||||
/// flat blue silhouette. Same approach as AswidSpectralClaw.ApplySpectralVisual, and like
|
||||
/// that one it copies each material first so the vanilla asset is never touched.
|
||||
/// </summary>
|
||||
public static void Apply(GameObject root)
|
||||
{
|
||||
if (root == null) return;
|
||||
|
||||
foreach (Renderer renderer in root.GetComponentsInChildren<Renderer>(true))
|
||||
{
|
||||
if (renderer == null || renderer is ParticleSystemRenderer) continue;
|
||||
|
||||
Material[] source = renderer.sharedMaterials;
|
||||
Material[] tinted = new Material[source.Length];
|
||||
for (int i = 0; i < source.Length; i++)
|
||||
{
|
||||
if (source[i] == null) continue;
|
||||
|
||||
Material material = new Material(source[i]);
|
||||
if (material.HasProperty("_Color"))
|
||||
{
|
||||
Color baseColor = material.GetColor("_Color");
|
||||
material.SetColor("_Color", new Color(baseColor.r * Albedo.r,
|
||||
baseColor.g * Albedo.g,
|
||||
baseColor.b * Albedo.b,
|
||||
baseColor.a));
|
||||
}
|
||||
if (material.HasProperty("_EmissionColor")) material.SetColor("_EmissionColor", Emission);
|
||||
|
||||
tinted[i] = material;
|
||||
}
|
||||
renderer.sharedMaterials = tinted;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,396 +0,0 @@
|
|||
using HarmonyLib;
|
||||
using Jotunn.Configs;
|
||||
using Jotunn.Entities;
|
||||
using Jotunn.Managers;
|
||||
using UnityEngine;
|
||||
|
||||
namespace RacesOfValheim
|
||||
{
|
||||
/// <summary>
|
||||
/// The one ice palette the whole Skadi chain shares. Taken from the Fader recolour in
|
||||
/// SkadiRace.ExecuteTransformation rather than picked fresh, so the staff, the reagent and the
|
||||
/// portal are all the same ice as the Skeleton Dragon the race turns into at tier 8.
|
||||
/// </summary>
|
||||
public static class SkadiIce
|
||||
{
|
||||
public static readonly Color Albedo = new Color(0.6f, 0.8f, 1f, 1f);
|
||||
public static readonly Color Emission = new Color(0f, 0.5f, 1f, 1f);
|
||||
public static readonly Color PortalSwirl = new Color(0.55f, 0.85f, 1f, 1f);
|
||||
|
||||
/// <summary>
|
||||
/// Multiplies the ice tint over whatever the base texture already carries instead of
|
||||
/// overwriting it, so the model keeps its detail and reads as frozen bone rather than as a
|
||||
/// flat blue silhouette. Same approach as AswidSpectralClaw.ApplySpectralVisual, and like
|
||||
/// that one it copies each material first so the vanilla asset is never touched.
|
||||
/// </summary>
|
||||
public static void Apply(GameObject root)
|
||||
{
|
||||
if (root == null) return;
|
||||
|
||||
foreach (Renderer renderer in root.GetComponentsInChildren<Renderer>(true))
|
||||
{
|
||||
if (renderer == null || renderer is ParticleSystemRenderer) continue;
|
||||
|
||||
Material[] source = renderer.sharedMaterials;
|
||||
Material[] tinted = new Material[source.Length];
|
||||
for (int i = 0; i < source.Length; i++)
|
||||
{
|
||||
if (source[i] == null) continue;
|
||||
|
||||
Material material = new Material(source[i]);
|
||||
if (material.HasProperty("_Color"))
|
||||
{
|
||||
Color baseColor = material.GetColor("_Color");
|
||||
material.SetColor("_Color", new Color(baseColor.r * Albedo.r,
|
||||
baseColor.g * Albedo.g,
|
||||
baseColor.b * Albedo.b,
|
||||
baseColor.a));
|
||||
}
|
||||
if (material.HasProperty("_EmissionColor")) material.SetColor("_EmissionColor", Emission);
|
||||
|
||||
tinted[i] = material;
|
||||
}
|
||||
renderer.sharedMaterials = tinted;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Skadis Nokkel - "Skadi's key". A StaffSkeleton with the skeleton taken out of it: it costs no
|
||||
/// eitr, no health and no stamina, it summons nothing, and what it does instead is open a portal
|
||||
/// into the player's own hidden hollow (SkadiHollow).
|
||||
///
|
||||
/// The name is the point. It is not a weapon that happens to open a door, it is a key - and a
|
||||
/// reproducible one: losing it costs a trip to the forge, not the hollow.
|
||||
///
|
||||
/// Two layers keep the vanilla staff's behaviour from leaking through, deliberately overlapping:
|
||||
/// - every field that could carry a cost or a summon is zeroed on the clone (Strip below);
|
||||
/// - the attack trigger itself is intercepted and vanilla's never runs for this staff
|
||||
/// (SkadiNokkelCastPatch). Nulling a projectile field would leave vanilla walking into it;
|
||||
/// taking over the method means that code path is not merely defused, it is unreachable.
|
||||
/// </summary>
|
||||
public static class SkadiNokkel
|
||||
{
|
||||
public const string PrefabName = "SkadiNokkel";
|
||||
public const string DisplayName = "Skadis Nokkel";
|
||||
private const string SourcePrefab = "StaffSkeleton";
|
||||
|
||||
private const string ModerDrop = "DragonTear";
|
||||
private const string SkullTrophy = "TrophySkeleton";
|
||||
|
||||
public static void Register()
|
||||
{
|
||||
GameObject prefab = PrefabManager.Instance.CreateClonedPrefab(PrefabName, SourcePrefab);
|
||||
if (prefab == null)
|
||||
{
|
||||
Jotunn.Logger.LogWarning($"[Skadi] Could not clone {SourcePrefab}; {DisplayName} not registered.");
|
||||
return;
|
||||
}
|
||||
|
||||
ItemDrop drop = prefab.GetComponent<ItemDrop>();
|
||||
if (drop == null || drop.m_itemData == null || drop.m_itemData.m_shared == null)
|
||||
{
|
||||
Jotunn.Logger.LogWarning($"[Skadi] {SourcePrefab} clone has no usable ItemDrop; {DisplayName} not registered.");
|
||||
return;
|
||||
}
|
||||
|
||||
ItemDrop.ItemData.SharedData shared = drop.m_itemData.m_shared;
|
||||
shared.m_name = DisplayName;
|
||||
shared.m_description = "A staff of frozen bone. It raises nothing. Used, it opens the way to a hollow " +
|
||||
"that is yours and no one else's - and used again, it lets you out.";
|
||||
shared.m_useDurability = false;
|
||||
|
||||
// ItemType is left exactly as the vanilla staff has it, on purpose: it decides the
|
||||
// equip slot and which animation set the character uses, and the cast gesture is the
|
||||
// whole reason this is a staff and not a trinket.
|
||||
|
||||
Strip(shared);
|
||||
SkadiIce.Apply(prefab);
|
||||
|
||||
ItemManager.Instance.AddItem(new CustomItem(prefab, fixReference: false));
|
||||
|
||||
LogCosts("straight after registering", shared);
|
||||
|
||||
ItemManager.Instance.AddRecipe(new CustomRecipe(new RecipeConfig
|
||||
{
|
||||
Item = PrefabName,
|
||||
Amount = 1,
|
||||
CraftingStation = CraftingStations.Forge,
|
||||
Requirements = new[]
|
||||
{
|
||||
new RequirementConfig(SkadiFrostHeart.PrefabName, 1, 0, true),
|
||||
new RequirementConfig(ModerDrop, 1, 0, true),
|
||||
new RequirementConfig(SkullTrophy, 1, 0, true),
|
||||
},
|
||||
}));
|
||||
|
||||
Jotunn.Logger.LogInfo($"[Skadi] {DisplayName} registered: no eitr, no health, no summon.");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Takes the skeleton staff apart. Every field is zeroed on BOTH attacks, because the
|
||||
/// secondary is a separate Attack with its own copy of every cost.
|
||||
///
|
||||
/// The summon is the interesting one: it comes from a SpawnAbility component (verified class,
|
||||
/// field GameObject[] m_spawnPrefab) which does not live on the item but on a prefab hung off
|
||||
/// the attack. WHICH field hangs it - m_attackProjectile or m_spawnOnTrigger - is not
|
||||
/// knowable from the game files, so all of them go. Nulling three fields that might each be
|
||||
/// the culprit costs nothing; guessing wrong costs a skeleton every cast.
|
||||
///
|
||||
/// m_attackStamina goes to zero too, and that is a decision, not thoroughness: the moment
|
||||
/// someone wants to flee into their hollow is exactly the moment they have no stamina left.
|
||||
/// The only brake on this staff is its cooldown.
|
||||
/// </summary>
|
||||
private static void Strip(ItemDrop.ItemData.SharedData shared)
|
||||
{
|
||||
StripAttack(shared.m_attack);
|
||||
StripAttack(shared.m_secondaryAttack);
|
||||
}
|
||||
|
||||
private static void StripAttack(Attack attack)
|
||||
{
|
||||
if (attack == null) return;
|
||||
|
||||
attack.m_attackEitr = 0f;
|
||||
attack.m_drawEitrDrain = 0f;
|
||||
attack.m_reloadEitrDrain = 0f;
|
||||
|
||||
attack.m_attackHealth = 0f;
|
||||
attack.m_attackHealthPercentage = 0f;
|
||||
attack.m_attackHealthLowBlockUse = false;
|
||||
attack.m_attackHealthReturnHit = 0f;
|
||||
|
||||
attack.m_attackStamina = 0f;
|
||||
attack.m_drawStaminaDrain = 0f;
|
||||
attack.m_reloadStaminaDrain = 0f;
|
||||
|
||||
attack.m_attackProjectile = null;
|
||||
attack.m_spawnOnTrigger = null;
|
||||
attack.m_spawnOnHit = null;
|
||||
attack.m_spawnOnHitChance = 0f;
|
||||
|
||||
// The animation stays. It is the summoning gesture, which is the right gesture for
|
||||
// opening a way, and it is the same one TrentaAbilities plays by hand for its portal.
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Runs on the cast. Race-gated: the hollow belongs to the Skadi, so in anyone else's hands
|
||||
/// this is an inert stick - the same shape as Aswid_SpectralClawDamage_Patch, which asks
|
||||
/// AswidRace.IsAswid() before doing anything at all.
|
||||
/// </summary>
|
||||
public static void OnCast(Player player)
|
||||
{
|
||||
if (player == null || player != Player.m_localPlayer) return;
|
||||
|
||||
if (!SkadiRace.IsLocalSkadi())
|
||||
{
|
||||
player.Message(MessageHud.MessageType.Center, "The staff is cold and answers to someone else.");
|
||||
return;
|
||||
}
|
||||
|
||||
SkadiHollow.Cast(player);
|
||||
}
|
||||
|
||||
public static bool IsNokkel(ItemDrop.ItemData item)
|
||||
{
|
||||
return item != null && item.m_dropPrefab != null && item.m_dropPrefab.name == PrefabName;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// True when a cost being asked about belongs to this staff.
|
||||
///
|
||||
/// The fallback on the equipped weapon is not belt-and-braces, it is necessary: the cost
|
||||
/// getters are called from Attack.Start, and m_weapon is not guaranteed to have been assigned
|
||||
/// by the time the cost is checked. It is deliberately only consulted when m_weapon is null,
|
||||
/// so a creature's own attack cannot be zeroed just because the player happens to be holding
|
||||
/// the staff at the time.
|
||||
/// </summary>
|
||||
public static bool IsNokkelContext(ItemDrop.ItemData weapon)
|
||||
{
|
||||
if (weapon != null) return IsNokkel(weapon);
|
||||
|
||||
Player local = Player.m_localPlayer;
|
||||
return local != null && IsNokkel(local.GetCurrentWeapon());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Prints what the clone's attack actually costs, so "the eitr cost came back" stops being a
|
||||
/// mystery and becomes a number with a timestamp. Called once at registration and again from
|
||||
/// the F8 dump, which between them say whether the zeroes were never written or were written
|
||||
/// and then overwritten by something else.
|
||||
/// </summary>
|
||||
public static void LogCosts(string when, ItemDrop.ItemData.SharedData shared)
|
||||
{
|
||||
if (shared == null) { Jotunn.Logger.LogWarning($"[Skadi] Nokkel costs {when}: no shared data."); return; }
|
||||
|
||||
Attack primary = shared.m_attack;
|
||||
Attack secondary = shared.m_secondaryAttack;
|
||||
|
||||
Jotunn.Logger.LogInfo($"[Skadi] Nokkel costs {when}: " +
|
||||
$"primary eitr={Describe(primary, a => a.m_attackEitr)} " +
|
||||
$"health={Describe(primary, a => a.m_attackHealth)} " +
|
||||
$"health%={Describe(primary, a => a.m_attackHealthPercentage)} " +
|
||||
$"stamina={Describe(primary, a => a.m_attackStamina)} | " +
|
||||
$"secondary eitr={Describe(secondary, a => a.m_attackEitr)} " +
|
||||
$"stamina={Describe(secondary, a => a.m_attackStamina)}");
|
||||
}
|
||||
|
||||
private static string Describe(Attack attack, System.Func<Attack, float> read)
|
||||
{
|
||||
return attack == null ? "<no attack>" : read(attack).ToString("0.##");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// What the F8 dump prints for this chain. Two unknowns, both settled by reading them once
|
||||
/// off a running game: which field of the vanilla staff carries the summon, and what the
|
||||
/// troll cave location is really called in this build.
|
||||
/// </summary>
|
||||
public static void DumpSource()
|
||||
{
|
||||
Jotunn.Logger.LogInfo("=== SKADI NOKKEL SOURCE DUMP ===");
|
||||
|
||||
GameObject staff = PrefabManager.Cache.GetPrefab<GameObject>(SourcePrefab);
|
||||
ItemDrop staffDrop = staff != null ? staff.GetComponent<ItemDrop>() : null;
|
||||
if (staffDrop == null)
|
||||
{
|
||||
Jotunn.Logger.LogWarning($"{SourcePrefab} not found.");
|
||||
}
|
||||
else
|
||||
{
|
||||
Attack attack = staffDrop.m_itemData.m_shared.m_attack;
|
||||
Jotunn.Logger.LogInfo($" m_attackType : {attack.m_attackType}");
|
||||
Jotunn.Logger.LogInfo($" m_attackAnimation : {attack.m_attackAnimation}");
|
||||
Jotunn.Logger.LogInfo($" m_attackProjectile : {(attack.m_attackProjectile != null ? attack.m_attackProjectile.name : "<null>")}");
|
||||
Jotunn.Logger.LogInfo($" m_spawnOnTrigger : {(attack.m_spawnOnTrigger != null ? attack.m_spawnOnTrigger.name : "<null>")}");
|
||||
Jotunn.Logger.LogInfo($" m_attackEitr : {attack.m_attackEitr}");
|
||||
Jotunn.Logger.LogInfo($" m_attackHealth : {attack.m_attackHealth} / {attack.m_attackHealthPercentage}%");
|
||||
|
||||
foreach (GameObject candidate in new[] { attack.m_attackProjectile, attack.m_spawnOnTrigger })
|
||||
{
|
||||
if (candidate == null) continue;
|
||||
foreach (SpawnAbility ability in candidate.GetComponentsInChildren<SpawnAbility>(true))
|
||||
{
|
||||
string spawns = "<none>";
|
||||
if (ability.m_spawnPrefab != null && ability.m_spawnPrefab.Length > 0)
|
||||
{
|
||||
string[] names = new string[ability.m_spawnPrefab.Length];
|
||||
for (int i = 0; i < names.Length; i++)
|
||||
{
|
||||
names[i] = ability.m_spawnPrefab[i] != null ? ability.m_spawnPrefab[i].name : "<null>";
|
||||
}
|
||||
spawns = string.Join(", ", names);
|
||||
}
|
||||
Jotunn.Logger.LogInfo($" SpawnAbility on '{candidate.name}' spawns: {spawns}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// The clone as the game currently holds it, not as Register() left it. If these are not
|
||||
// zero, the write in Strip() did not survive - which is the whole reason
|
||||
// SkadiNokkelFreeCastPatch exists, and this line is how we find out whether it is still
|
||||
// needed or whether the fields hold after all.
|
||||
GameObject clone = PrefabManager.Cache.GetPrefab<GameObject>(PrefabName);
|
||||
ItemDrop cloneDrop = clone != null ? clone.GetComponent<ItemDrop>() : null;
|
||||
if (cloneDrop == null)
|
||||
{
|
||||
Jotunn.Logger.LogWarning($" {PrefabName} is not in the prefab cache.");
|
||||
}
|
||||
else
|
||||
{
|
||||
LogCosts("as the game holds it now", cloneDrop.m_itemData.m_shared);
|
||||
Jotunn.Logger.LogInfo($" shared data instance is {(ReferenceEquals(cloneDrop.m_itemData.m_shared, staffDrop != null ? staffDrop.m_itemData.m_shared : null) ? "THE SAME OBJECT as the vanilla staff's - that is the bug" : "its own copy, as expected")}");
|
||||
}
|
||||
|
||||
// The other half: is 'TrollCave02' actually what it is called here?
|
||||
Jotunn.Logger.LogInfo($"--- locations matching 'cave' (looking for {SkadiHollow.SourceLocation}) ---");
|
||||
if (ZoneSystem.instance == null || ZoneSystem.instance.m_locations == null)
|
||||
{
|
||||
Jotunn.Logger.LogWarning(" ZoneSystem not up yet; load a world first.");
|
||||
}
|
||||
else
|
||||
{
|
||||
// m_locations, not GetLocationList(): the latter is public but returns the locations
|
||||
// PLACED in this world, and the hollow needs the definition, not an instance.
|
||||
foreach (ZoneSystem.ZoneLocation location in ZoneSystem.instance.m_locations)
|
||||
{
|
||||
if (location == null || string.IsNullOrEmpty(location.m_prefabName)) continue;
|
||||
if (location.m_prefabName.IndexOf("cave", System.StringComparison.OrdinalIgnoreCase) < 0) continue;
|
||||
|
||||
Jotunn.Logger.LogInfo($" {location.m_prefabName} (biome {location.m_biome}, " +
|
||||
$"interior r{location.m_interiorRadius}, clearArea {location.m_clearArea})");
|
||||
}
|
||||
}
|
||||
|
||||
Jotunn.Logger.LogInfo("=== END SKADI NOKKEL SOURCE DUMP ===");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The cast hook, and the second half of "remove the unwanted components".
|
||||
///
|
||||
/// Attack.OnAttackTrigger() is used rather than Attack.Start because it takes NO parameters -
|
||||
/// its signature cannot drift and cannot be got wrong, which matters here because Attack.Start's
|
||||
/// parameter types could not even be loaded for inspection outside the game. It also fires at
|
||||
/// the moment the animation reaches its release point, which is exactly when a cast should land.
|
||||
///
|
||||
/// It is a Prefix returning FALSE, not a postfix, and that is the whole trick: for this staff
|
||||
/// vanilla's attack-trigger code never executes at all. The summon and the projectile are not
|
||||
/// just defused by the zeroed fields, they are unreachable - and vanilla cannot trip over the
|
||||
/// nulls we left behind either, which a postfix would have been at the mercy of.
|
||||
///
|
||||
/// m_weapon and m_character are both PRIVATE on Attack, so they arrive through Harmony's triple
|
||||
/// underscore field injection rather than off __instance - which is also why they are spelled
|
||||
/// out here instead of being read with Traverse: the injection is checked at patch time, so a
|
||||
/// rename shows up as a startup error instead of a silent null every cast.
|
||||
/// </summary>
|
||||
[HarmonyPatch(typeof(Attack), "OnAttackTrigger")]
|
||||
public static class SkadiNokkelCastPatch
|
||||
{
|
||||
public static bool Prefix(ItemDrop.ItemData ___m_weapon, Humanoid ___m_character)
|
||||
{
|
||||
if (!SkadiNokkel.IsNokkel(___m_weapon)) return true;
|
||||
|
||||
SkadiNokkel.OnCast(___m_character as Player);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The staff costs nothing, guaranteed - and this is what guarantees it.
|
||||
///
|
||||
/// Zeroing m_attackEitr, m_attackHealth and m_attackStamina on the clone is still done in
|
||||
/// Strip(), and by every reading of the game's own code it ought to be enough: those three, plus
|
||||
/// the two drain fields, are the ONLY eitr costs that exist anywhere on Attack, and SharedData
|
||||
/// carries none at all (checked field by field). In game the cost came back anyway, which means
|
||||
/// the write to the clone's own SharedData does not survive something - so relying on that write
|
||||
/// is relying on a mechanism that has already been observed to fail.
|
||||
///
|
||||
/// These three getters are the single funnel every cost check flows through: Attack.Start asks
|
||||
/// them before it will start, and the tooltip asks them for what to print. Forcing them to zero
|
||||
/// makes the staff free no matter what any field says, which is the same reasoning as the prefix
|
||||
/// above - do not defuse the code path, remove it.
|
||||
///
|
||||
/// All three are PRIVATE and take no parameters, so they are addressed by name through
|
||||
/// AccessTools and share one postfix.
|
||||
/// </summary>
|
||||
[HarmonyPatch]
|
||||
public static class SkadiNokkelFreeCastPatch
|
||||
{
|
||||
[HarmonyTargetMethods]
|
||||
private static System.Collections.Generic.IEnumerable<System.Reflection.MethodBase> TargetMethods()
|
||||
{
|
||||
yield return AccessTools.Method(typeof(Attack), "GetAttackEitr");
|
||||
yield return AccessTools.Method(typeof(Attack), "GetAttackHealth");
|
||||
yield return AccessTools.Method(typeof(Attack), "GetAttackStamina");
|
||||
}
|
||||
|
||||
[HarmonyPostfix]
|
||||
private static void Postfix(ItemDrop.ItemData ___m_weapon, ref float __result)
|
||||
{
|
||||
if (__result == 0f) return;
|
||||
if (!SkadiNokkel.IsNokkelContext(___m_weapon)) return;
|
||||
|
||||
__result = 0f;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -33,7 +33,6 @@ namespace RacesOfValheim
|
|||
// rebuild - see CONFIGURATION-MANAGER-HOWTO.md.
|
||||
public const string SPELL_COOLDOWN_SE = "SE_SkadiSpellCooldown";
|
||||
public const string ATTACK_COOLDOWN_SE = "SE_SkadiAttackCooldown";
|
||||
public const string HOLLOW_COOLDOWN_SE = "SE_SkadiHollowCooldown";
|
||||
|
||||
private static float SPELL_STAMINA_COST => SkadiConfig.SpellStaminaCost.Value;
|
||||
private static float SPELL_COOLDOWN => SkadiConfig.SpellCooldown.Value;
|
||||
|
|
@ -53,9 +52,9 @@ namespace RacesOfValheim
|
|||
{
|
||||
// The reagent goes first: the faction merchant catalogue resolves its entries by prefab
|
||||
// name, so Greater Frost Heart has to exist before a Fenring_Cultist is ever set up as a
|
||||
// bench - and the staff's recipe references it by name too.
|
||||
// bench.
|
||||
SkadiFrostHeart.Register();
|
||||
SkadiNokkel.Register();
|
||||
SkadiGolem.Register();
|
||||
|
||||
var se = ScriptableObject.CreateInstance<SE_SkadiStats>();
|
||||
se.name = "SE_SkadiStats";
|
||||
|
|
@ -108,13 +107,6 @@ namespace RacesOfValheim
|
|||
attackCd.m_tooltip = "Your dragon shape must ready itself to strike again.";
|
||||
attackCd.m_icon = GetItemIcon("TrophyHatchling") ?? dragonIcon;
|
||||
ItemManager.Instance.AddStatusEffect(new CustomStatusEffect(attackCd, fixReference: false));
|
||||
|
||||
var hollowCd = ScriptableObject.CreateInstance<SE_SkadiAbilityCooldown>();
|
||||
hollowCd.name = HOLLOW_COOLDOWN_SE;
|
||||
hollowCd.m_name = "Skadis Nokkel";
|
||||
hollowCd.m_tooltip = "The way to your hollow must freeze over again before it will open.";
|
||||
hollowCd.m_icon = GetItemIcon("StaffIceShards") ?? dragonIcon;
|
||||
ItemManager.Instance.AddStatusEffect(new CustomStatusEffect(hollowCd, fixReference: false));
|
||||
}
|
||||
|
||||
// Drives the HUD countdown: Valheim prints the remaining time on any status effect whose
|
||||
|
|
@ -151,8 +143,8 @@ namespace RacesOfValheim
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// The same check, reachable without an Instance - which the Nokkel's Harmony patch and the
|
||||
/// hollow both need, since they run from static context.
|
||||
/// The same check, reachable without an Instance - which the golem and the cave-building
|
||||
/// watcher both need, since they run from static context.
|
||||
/// </summary>
|
||||
public static bool IsLocalSkadi()
|
||||
{
|
||||
|
|
@ -254,8 +246,7 @@ namespace RacesOfValheim
|
|||
DumpPrefabDebugInfo("Dragon");
|
||||
DumpPrefabDebugInfo("Hatchling");
|
||||
DumpPrefabDebugInfo("Fader");
|
||||
SkadiNokkel.DumpSource();
|
||||
if (Player.m_localPlayer != null) Player.m_localPlayer.Message(MessageHud.MessageType.Center, "Dumped Dragon/Drake/Fader + Nokkel debug info to console!");
|
||||
if (Player.m_localPlayer != null) Player.m_localPlayer.Message(MessageHud.MessageType.Center, "Dumped Dragon/Drake/Fader debug info to console!");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue