102 lines
4.3 KiB
C#
102 lines
4.3 KiB
C#
using UnityEngine;
|
|
|
|
namespace RacesOfValheim
|
|
{
|
|
/// <summary>
|
|
/// Driver for the Sverm: an armoured insect that never dresses, never disarms, and grows a
|
|
/// colony instead of a wardrobe.
|
|
///
|
|
/// Only the per-frame upkeep that does not belong to a Harmony hook lives here. The perks are
|
|
/// SvermPatches, the passive is SE_SvermStats, the numbers are SvermConfig by way of
|
|
/// SvermProgression, and the look is SvermVisuals.
|
|
/// </summary>
|
|
public class SvermRace : MonoBehaviour
|
|
{
|
|
public static SvermRace Instance;
|
|
|
|
private float nextStatePublish;
|
|
|
|
private void Awake()
|
|
{
|
|
Instance = this;
|
|
}
|
|
|
|
public void CreateModAssets()
|
|
{
|
|
SvermStatusEffects.RegisterStatusEffects();
|
|
|
|
// Registered HERE and not lazily at spawn: this method runs on
|
|
// PrefabManager.OnVanillaPrefabsAvailable, which is the one moment Jotunn will take a
|
|
// new item into ObjectDB. Registering later builds a prefab nobody can spawn.
|
|
SvermClawSlot.EnsureRegistered();
|
|
|
|
// Same window, same reason: every edible is a cloned item, and Jotunn only takes new
|
|
// items here.
|
|
SvermFood.Register();
|
|
|
|
// Same window again: the worker is a cloned creature prefab.
|
|
SvermWorker.Register();
|
|
|
|
// And the four troops, which are cloned creatures too - Jotunn only takes a new prefab
|
|
// in this window, so a roster registered later is a roster nothing can spawn.
|
|
SvermBrood.Register();
|
|
|
|
// The bomb tick is a cloned creature too, and its blast is priced off two vanilla
|
|
// projectiles it reads at registration.
|
|
SvermBlisterTick.Register();
|
|
|
|
// The nest, its density cap and its Elder gate all live in SvermHive now.
|
|
//
|
|
// HONEST LIMIT on that cap, and it is PieceDensityLimit's own: a client holds only the
|
|
// ZDOs the server has sent it, and 908 m is far outside the loaded zones. Exact in
|
|
// singleplayer and on the host; on a remote client it can undercount and let a third
|
|
// nest through far from the other two. It still closes the case that matters.
|
|
SvermHive.Register();
|
|
|
|
// The shop counter, a building of its own rather than a second mouth on the nest - two
|
|
// 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();
|
|
}
|
|
|
|
public static bool IsSverm()
|
|
{
|
|
return Player.m_localPlayer != null &&
|
|
Player.m_localPlayer.m_customData.ContainsKey("Race") &&
|
|
Player.m_localPlayer.m_customData["Race"] == SvermConfig.RaceId;
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
// Antennae first and outside the race guard: it has to be able to put its own lights
|
|
// out when the player stops being a Sverm, and a guard above it would leave them lit
|
|
// on every creature in range forever.
|
|
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);
|
|
|
|
if (Player.m_localPlayer == null || !IsSverm()) return;
|
|
|
|
// Republished on a timer rather than only at spawn: the tier changes the moment a boss
|
|
// dies, and a remote Sverm that still reads as tier 4 renders in the wrong colour with
|
|
// the wrong wings until it next loads.
|
|
if (Time.time >= nextStatePublish)
|
|
{
|
|
nextStatePublish = Time.time + 5f;
|
|
SvermPatches.PublishState(Player.m_localPlayer);
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Names the colony half will register, declared here so the body half can cap the hive before
|
|
/// that half exists. One string, one place, no duplicate literal to drift.
|
|
/// </summary>
|
|
public static class SvermHiveNames
|
|
{
|
|
public const string PieceName = "SvermBroodMound";
|
|
public const string PieceDisplayName = "Brood Mound";
|
|
}
|
|
}
|