warvulture
This commit is contained in:
parent
3095198539
commit
1d66b00374
29 changed files with 7236 additions and 4 deletions
621
JotunnModStub/Sverm/SvermHive.cs
Normal file
621
JotunnModStub/Sverm/SvermHive.cs
Normal file
|
|
@ -0,0 +1,621 @@
|
|||
using System.Collections.Generic;
|
||||
using Jotunn.Configs;
|
||||
using Jotunn.Entities;
|
||||
using Jotunn.Managers;
|
||||
using UnityEngine;
|
||||
|
||||
namespace RacesOfValheim
|
||||
{
|
||||
/// <summary>
|
||||
/// The nest itself: the piece, its gate, and the ten metres of ground it claims.
|
||||
///
|
||||
/// GATED ON THE ELDER, and that gate is the whole point of the revision. The colony used to
|
||||
/// open at tier 1 and arrive all at once; now the early game is spent as a body, and the first
|
||||
/// nest is a thing you earn. What the boss decides is WHEN you may plant one - how fast it
|
||||
/// grows after that is still bought with biomass, four stages at the shop, exactly as before.
|
||||
///
|
||||
/// THE AURA is what makes it read as a colony rather than as a machine. Inside ten metres the
|
||||
/// Sverm may raise up to ten vanilla beehives, and they cost only wood - no queen bee, because
|
||||
/// a colony that has to go hunting for someone else's queen is telling the wrong story. Left
|
||||
/// alone for a minute, each hive is taken over: an egg pushes out through the roof, and from
|
||||
/// then on it works twice as fast and holds three times as much.
|
||||
///
|
||||
/// This file owns the piece and the aura. Biomass, eggs, troops and the shop are
|
||||
/// SvermHiveBehaviour's; the workers are SvermWorker's.
|
||||
/// </summary>
|
||||
public static class SvermHive
|
||||
{
|
||||
public const string PieceName = SvermHiveNames.PieceName;
|
||||
public const string DisplayName = SvermHiveNames.PieceDisplayName;
|
||||
|
||||
/// <summary>
|
||||
/// What the nest borrows its body from, best first.
|
||||
///
|
||||
/// "Hive" WAS the first entry and it was a disaster. The name is in the game's manifest and
|
||||
/// it sounds exactly right, so it went in unchecked - and it turned out to carry a
|
||||
/// Character. Building it did not place a nest, it SPAWNED A CREATURE, and because a Piece
|
||||
/// and a WearNTear had been bolted on top without removing anything, the health the console
|
||||
/// tried to take off was not the health holding it up. A giant immortal Bonemass, from a
|
||||
/// name that read as scenery.
|
||||
///
|
||||
/// Everything in this list now is a CreepProp - the game's own word for "this is a prop" -
|
||||
/// and IsSafeScenery below refuses anything alive whatever the list says.
|
||||
/// </summary>
|
||||
private static readonly string[] SourceCandidates =
|
||||
{
|
||||
"CreepProp_pillar01",
|
||||
"CreepProp_egg_hanging01",
|
||||
"Creeppillar",
|
||||
"CreepProp_hanging01",
|
||||
};
|
||||
|
||||
public static void Register()
|
||||
{
|
||||
GameObject prefab = null;
|
||||
string sourcePrefab = null;
|
||||
|
||||
foreach (string candidate in SourceCandidates)
|
||||
{
|
||||
GameObject source = PrefabManager.Cache.GetPrefab<GameObject>(candidate);
|
||||
if (source == null) continue;
|
||||
|
||||
if (!IsSafeScenery(source, candidate)) continue;
|
||||
|
||||
prefab = PrefabManager.Instance.CreateClonedPrefab(PieceName, source);
|
||||
if (prefab == null) continue;
|
||||
|
||||
sourcePrefab = candidate;
|
||||
break;
|
||||
}
|
||||
|
||||
if (prefab == null)
|
||||
{
|
||||
Jotunn.Logger.LogWarning("[Sverm] No safe scenery to build the nest from (" +
|
||||
string.Join(", ", SourceCandidates) + "); the nest is not registered. " +
|
||||
"Not registering is the correct outcome: a nest nobody can build beats " +
|
||||
"a nest that turns out to be alive.");
|
||||
return;
|
||||
}
|
||||
|
||||
// Belt as well as braces: anything that could still make this act like a creature comes
|
||||
// off the COPY. The guard above should mean there is nothing to find, and this is what
|
||||
// makes that true rather than hoped for.
|
||||
StripLife(prefab);
|
||||
|
||||
// Set on the PREFAB, so every nest ever placed comes out this size and the value is
|
||||
// baked into the piece rather than chased at runtime. It follows that changing it in
|
||||
// the .cfg only affects nests placed afterwards - the ones already standing keep the
|
||||
// size they were built at, which is how every other building in the game behaves.
|
||||
float scale = SvermConfigManagement.HiveScale;
|
||||
prefab.transform.localScale = new Vector3(scale, scale, scale);
|
||||
|
||||
// A hive in the world is scenery, not a building: it arrives with no Piece and no
|
||||
// WearNTear, and the hammer needs both. Added rather than assumed - the clone is
|
||||
// whatever the game shipped, and asking for a component that is not there is how a
|
||||
// station ends up unplaceable with no error.
|
||||
Piece piece = prefab.GetComponent<Piece>() ?? prefab.AddComponent<Piece>();
|
||||
piece.m_name = DisplayName;
|
||||
piece.m_description = "The colony begins here. Everything else grows out of it.";
|
||||
piece.m_groundPiece = true;
|
||||
piece.m_groundOnly = true;
|
||||
piece.m_cultivatedGroundOnly = false;
|
||||
piece.m_canBeRemoved = true;
|
||||
|
||||
if (prefab.GetComponent<WearNTear>() == null)
|
||||
{
|
||||
WearNTear wear = prefab.AddComponent<WearNTear>();
|
||||
wear.m_health = 1500f;
|
||||
wear.m_noRoofWear = true;
|
||||
wear.m_noSupportWear = true;
|
||||
wear.m_destroyedEffect = new EffectList();
|
||||
wear.m_hitEffect = new EffectList();
|
||||
}
|
||||
|
||||
if (prefab.GetComponent<ZNetView>() == null) prefab.AddComponent<ZNetView>();
|
||||
prefab.AddComponent<SvermHiveBehaviour>();
|
||||
|
||||
MountMouths(prefab);
|
||||
|
||||
PieceManager.Instance.AddPiece(new CustomPiece(prefab, fixReference: false, new PieceConfig
|
||||
{
|
||||
Name = DisplayName,
|
||||
Description = piece.m_description,
|
||||
PieceTable = PieceTables.Hammer,
|
||||
Category = "Crafting",
|
||||
|
||||
// NOT OPTIONAL. Jotunn refuses a piece with no icon outright - "CustomPiece has no
|
||||
// icon" followed by "is not valid" - and the piece simply never reaches the
|
||||
// hammer. Borrowed off a trophy, the way SkeletonBonePile does.
|
||||
Icon = BorrowIcon("TrophySeekerBrute") ?? BorrowIcon("TrophySeeker") ?? BorrowIcon("Honey"),
|
||||
Requirements = new[]
|
||||
{
|
||||
new RequirementConfig { Item = "Wood", Amount = 40, Recover = true },
|
||||
new RequirementConfig { Item = "Resin", Amount = 20, Recover = true },
|
||||
},
|
||||
}));
|
||||
|
||||
// Two per square mile, as before. The radius is 908 m because that is the circle of
|
||||
// equal area, and PieceDensityLimit counts over ZDOs rather than loaded objects.
|
||||
PieceDensityLimit.Register(PieceName, SvermConfig.HiveDensityRadius, SvermConfig.HiveDensityMax,
|
||||
"There is already a hive holding this ground.");
|
||||
|
||||
// The gate. Race first, then the boss - two separate refusals, because "you are not a
|
||||
// Sverm" and "you have not killed The Elder" are different problems and a player who
|
||||
// gets the wrong message goes looking in the wrong place.
|
||||
PieceDensityLimit.RegisterGate(PieceName, (player, position) =>
|
||||
{
|
||||
if (player == null) return false;
|
||||
|
||||
if (!SvermVisuals.IsSvermPlayer(player))
|
||||
{
|
||||
player.Message(MessageHud.MessageType.Center, "Only the Sverm can raise a hive.");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (BossProgressionManager.GetCurrentProgressionState() < SvermConfig.HiveUnlockState)
|
||||
{
|
||||
player.Message(MessageHud.MessageType.Center, "The colony will not wake until the Elder falls.");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
});
|
||||
|
||||
Jotunn.Logger.LogInfo($"[Sverm] Registered '{PieceName}' from '{sourcePrefab}'.");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// What the two mouths borrow their look from, best first. SCENERY ONLY.
|
||||
///
|
||||
/// "Hive" WAS ON THIS LIST for one build, on the reasoning that ModelBorrow strips a copy
|
||||
/// down to its renderers so borrowing a living prefab is safe. IT IS NOT, and the game said
|
||||
/// so in one line nobody had asked it for:
|
||||
///
|
||||
/// Can't remove Humanoid (Script) because CharacterDrop (Script) depends on it
|
||||
///
|
||||
/// ModelBorrow's strip is a single pass in component order. Unity REFUSES to destroy a
|
||||
/// component another one still requires, so Humanoid survived on both mouths - and from then
|
||||
/// on every placement ghost woke a Humanoid, registered it in Character.s_characters and
|
||||
/// tore it down again, until Character.GetCharactersInRange threw on the wreckage inside
|
||||
/// Player.UpdatePlacementGhost. The hammer stopped working. FOR EVERY PIECE IN THE GAME, not
|
||||
/// just this one.
|
||||
///
|
||||
/// Which is house rule one, twice over: ask the prefab whether it has a Character, and do
|
||||
/// not trust a helper to have asked for you. IsSafeScenery below now runs on the source
|
||||
/// BEFORE anything is borrowed from it.
|
||||
/// </summary>
|
||||
private static readonly string[] MouthCandidates =
|
||||
{
|
||||
"TheHive",
|
||||
"CreepProp_egg_hanging01",
|
||||
"CreepProp_egg_hanging02",
|
||||
"SeekerEgg",
|
||||
"CreepProp_hanging01",
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// The stomach: the hive at the nest's foot that a press feeds.
|
||||
///
|
||||
/// A MOUTH AND NOT A MENU, at the player's call, after a sell panel inside the vanilla store
|
||||
/// came up empty and unclickable in game. Feeding is a press on a thing you can see, which
|
||||
/// needs no UI to be right.
|
||||
///
|
||||
/// THERE WAS A SECOND MOUTH UP THE TRUNK, the shop, and it is gone: it never had a height
|
||||
/// that worked. On the measured crown it was eight metres over the player's head; at the
|
||||
/// number that replaced it the .cfg still held the old zero, so it sat inside the stomach's
|
||||
/// own sphere and the ray always found the stomach first. The shop is its own building now -
|
||||
/// SvermHiveMarketPiece - which is how the Dvergar bench and the Trol totem already do it.
|
||||
///
|
||||
/// The mouth gets a SPHERE OF ITS OWN because Player.FindHoverObject picks what you are
|
||||
/// pointing at from the first collider the ray meets and reads the Hoverable off THAT
|
||||
/// collider's own GameObject. A mouth sharing the trunk's collider would not be a mouth. The
|
||||
/// sphere is as wide as the model, so it stands clear of the trunk rather than hiding inside
|
||||
/// it - the one thing that would make it unreachable.
|
||||
/// </summary>
|
||||
private static void MountMouths(GameObject prefab)
|
||||
{
|
||||
// Measured BEFORE the mouths are hung, or it would be measuring them too. This is the
|
||||
// trunk's own height, in the piece's local space, and it is what "up top" means when
|
||||
// nobody has typed a number into the .cfg.
|
||||
float trunk = ModelBorrow.HeightOf(prefab);
|
||||
|
||||
GameObject source = null;
|
||||
string sourceName = null;
|
||||
foreach (string candidate in MouthCandidates)
|
||||
{
|
||||
GameObject found = PrefabManager.Cache.GetPrefab<GameObject>(candidate);
|
||||
if (found == null) continue;
|
||||
|
||||
// The same question the piece itself has to answer, asked again here: a model is
|
||||
// borrowed from this, and a borrowed model that turns out to be alive is what broke
|
||||
// the hammer.
|
||||
if (!IsSafeScenery(found, candidate)) continue;
|
||||
|
||||
source = found;
|
||||
sourceName = candidate;
|
||||
break;
|
||||
}
|
||||
|
||||
if (source == null)
|
||||
{
|
||||
Jotunn.Logger.LogWarning("[Sverm] No safe scenery to borrow the nest's mouths from (" +
|
||||
string.Join(", ", MouthCandidates) + "); they are mounted " +
|
||||
"anyway, invisible but pressable, rather than leaving the " +
|
||||
"nest with no way to be fed.");
|
||||
}
|
||||
|
||||
// The trunk is REPORTED and not used as a height: it measured 10.59 m, which is the
|
||||
// number that made the old market unreachable. Kept in the log because it is the only
|
||||
// way anyone can tell where there is room to put something on this piece.
|
||||
Jotunn.Logger.LogInfo($"[Sverm] Nest stomach borrowed from '{sourceName ?? "nothing"}'; the trunk " +
|
||||
$"measures {trunk:0.##} m and the stomach sits at " +
|
||||
$"{SvermConfigManagement.StomachHeight:0.##} m.");
|
||||
|
||||
MountMouth<SvermHiveStomach>(prefab, source, "SvermHiveStomach",
|
||||
SvermConfigManagement.StomachSize, SvermConfigManagement.StomachHeight);
|
||||
}
|
||||
|
||||
private static void MountMouth<T>(GameObject prefab, GameObject source, string holderName,
|
||||
float size, float height) where T : SvermHiveMouth
|
||||
{
|
||||
GameObject holder = ModelBorrow.Attach(prefab.transform, holderName, source,
|
||||
new Vector3(0f, height, 0f), Quaternion.identity, size, "Sverm");
|
||||
|
||||
// The piece's own layer, because that is the layer the player's interact raycast looks
|
||||
// at. A GameObject built from scratch comes up on Default, and Default is not it.
|
||||
holder.layer = prefab.layer;
|
||||
|
||||
// Centred half a size up: ModelBorrow grounds a borrowed model on the holder's origin,
|
||||
// so the holder's origin is the model's FOOT and not its middle.
|
||||
SphereCollider ball = holder.AddComponent<SphereCollider>();
|
||||
ball.center = new Vector3(0f, size * 0.5f, 0f);
|
||||
ball.radius = size * 0.5f;
|
||||
|
||||
holder.AddComponent<T>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Refuses to build a building out of anything that is alive.
|
||||
///
|
||||
/// This is the check that was missing, and its absence cost a giant immortal Bonemass in
|
||||
/// somebody's base. A name in the asset manifest says nothing about what a prefab DOES -
|
||||
/// "Hive" carried a Character - and the only way to know is to ask the prefab itself.
|
||||
///
|
||||
/// It logs what it found rather than failing quietly, because the next person to add a
|
||||
/// station from a borrowed prefab needs to be told which one to stop trusting.
|
||||
/// </summary>
|
||||
internal static bool IsSafeScenery(GameObject source, string name)
|
||||
{
|
||||
if (source.GetComponentInChildren<Character>(true) != null)
|
||||
{
|
||||
Jotunn.Logger.LogWarning($"[Sverm] '{name}' carries a Character - it is a CREATURE, not scenery. " +
|
||||
"Refusing to make a building out of it.");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (source.GetComponentInChildren<BaseAI>(true) != null)
|
||||
{
|
||||
Jotunn.Logger.LogWarning($"[Sverm] '{name}' carries a BaseAI; refusing to make a building out of it.");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (source.GetComponentInChildren<SpawnArea>(true) != null)
|
||||
{
|
||||
Jotunn.Logger.LogWarning($"[Sverm] '{name}' is a spawner; refusing to make a building out of it.");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Takes everything that could still behave like a creature off the copy.
|
||||
///
|
||||
/// Order matters for the same reason it does in ModelBorrow: behaviours first, then the
|
||||
/// things they hold references to.
|
||||
/// </summary>
|
||||
internal static void StripLife(GameObject copy)
|
||||
{
|
||||
foreach (BaseAI ai in copy.GetComponentsInChildren<BaseAI>(true))
|
||||
{
|
||||
if (ai != null) Object.DestroyImmediate(ai);
|
||||
}
|
||||
foreach (Character character in copy.GetComponentsInChildren<Character>(true))
|
||||
{
|
||||
if (character != null) Object.DestroyImmediate(character);
|
||||
}
|
||||
foreach (CharacterDrop drop in copy.GetComponentsInChildren<CharacterDrop>(true))
|
||||
{
|
||||
if (drop != null) Object.DestroyImmediate(drop);
|
||||
}
|
||||
foreach (SpawnArea spawner in copy.GetComponentsInChildren<SpawnArea>(true))
|
||||
{
|
||||
if (spawner != null) Object.DestroyImmediate(spawner);
|
||||
}
|
||||
foreach (Rigidbody body in copy.GetComponentsInChildren<Rigidbody>(true))
|
||||
{
|
||||
if (body != null) Object.DestroyImmediate(body);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The nest this point belongs to, or null.
|
||||
///
|
||||
/// Loaded objects and not ZDOs, deliberately: the only caller is the market bench, which is
|
||||
/// standing inside the nest's ten metres or it would not have been allowed to exist. A nest
|
||||
/// that close is loaded by definition, and the cheap answer is the right one.
|
||||
/// </summary>
|
||||
internal static SvermHiveBehaviour NearestNest(Vector3 position, float radius)
|
||||
{
|
||||
SvermHiveBehaviour closest = null;
|
||||
float best = radius;
|
||||
|
||||
foreach (SvermHiveBehaviour nest in Object.FindObjectsOfType<SvermHiveBehaviour>())
|
||||
{
|
||||
if (nest == null) continue;
|
||||
|
||||
float distance = Vector3.Distance(nest.transform.position, position);
|
||||
if (distance > best) continue;
|
||||
|
||||
best = distance;
|
||||
closest = nest;
|
||||
}
|
||||
|
||||
return closest;
|
||||
}
|
||||
|
||||
/// <summary>An item's inventory icon, or null. Same helper shape as SkeletonBonePile's.</summary>
|
||||
internal static Sprite BorrowIcon(string prefabName)
|
||||
{
|
||||
ItemDrop drop = PrefabManager.Cache.GetPrefab<ItemDrop>(prefabName);
|
||||
if (drop == null || drop.m_itemData == null || drop.m_itemData.m_shared == null) return null;
|
||||
if (drop.m_itemData.m_shared.m_icons == null || drop.m_itemData.m_shared.m_icons.Length == 0) return null;
|
||||
return drop.m_itemData.m_shared.m_icons[0];
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The nest's own upkeep. Today that is the aura and the beehives inside it; biomass, eggs,
|
||||
/// troops and the shop land here next.
|
||||
/// </summary>
|
||||
public class SvermHiveBehaviour : MonoBehaviour, Hoverable, Interactable
|
||||
{
|
||||
/// <summary>
|
||||
/// The trunk feeds, exactly like the stomach at its foot.
|
||||
///
|
||||
/// IT USED TO TAKE WHAT WAS IN YOUR HAND, which could not be made to work: food is a
|
||||
/// consumable, it never reaches the weapon slot, and the meat the player thought they were
|
||||
/// offering was simply eaten by the player. It reads the inventory now.
|
||||
///
|
||||
/// The trunk is the widest thing to point at, so it does the thing you do most rather than
|
||||
/// being a dead spot between the two mouths. The store has one way in and it is the hive up
|
||||
/// top - see SvermHiveMarket.
|
||||
/// </summary>
|
||||
public bool Interact(Humanoid user, bool hold, bool alt)
|
||||
{
|
||||
if (hold) return false;
|
||||
|
||||
Player player = user as Player;
|
||||
if (player == null || player != Player.m_localPlayer) return false;
|
||||
|
||||
if (!SvermVisuals.IsSvermPlayer(player))
|
||||
{
|
||||
player.Message(MessageHud.MessageType.Center, "The hive does not know you.");
|
||||
return true;
|
||||
}
|
||||
|
||||
return SvermHiveStore.FeedOneStack(this, player);
|
||||
}
|
||||
|
||||
public bool UseItem(Humanoid user, ItemDrop.ItemData item) => false;
|
||||
|
||||
/// <summary>
|
||||
/// What the nest says when you look at it.
|
||||
///
|
||||
/// The tank had no readout at all in the first pass, which made every other part of the
|
||||
/// colony unfalsifiable: a hauler that was not working and a hauler that was working
|
||||
/// looked exactly the same. A number on the hive is the cheapest possible test of the
|
||||
/// whole chain.
|
||||
/// </summary>
|
||||
public string GetHoverText()
|
||||
{
|
||||
int beehives = SvermBeehive.CountInAura(transform.position);
|
||||
int infected = SvermBeehive.CountInfectedInAura(transform.position);
|
||||
|
||||
// Both numbers, always, even when nothing is going down. A line that appears and
|
||||
// disappears is one the player has to notice twice before they believe it.
|
||||
return $"{SvermHiveStage.NameOf(SvermHiveStage.Of(transform))}\n" +
|
||||
SvermHiveReadout.Tank(transform) +
|
||||
$"Beehives {infected} taken of {beehives} in range\n" +
|
||||
"[<color=yellow><b>$KEY_Use</b></color>] Feed it a stack";
|
||||
}
|
||||
|
||||
public string GetHoverName() => SvermHiveStage.NameOf(SvermHiveStage.Of(transform));
|
||||
|
||||
private ZNetView nview;
|
||||
private float nextSweep;
|
||||
private float nextHauler;
|
||||
private float nextDigest;
|
||||
private float nextTick;
|
||||
private float nextVfx;
|
||||
|
||||
/// <summary>
|
||||
/// The size this nest was built at, before any growth is applied on top.
|
||||
///
|
||||
/// Read at Awake and kept, rather than taken from the config each time: the piece is
|
||||
/// registered at the configured scale, so what the transform holds when it loads IS the size
|
||||
/// this particular nest was placed at - which is the promise the config makes, that changing
|
||||
/// it never resizes nests already standing.
|
||||
/// </summary>
|
||||
private Vector3 builtScale = Vector3.one;
|
||||
private float shownScale = -1f;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
nview = GetComponent<ZNetView>();
|
||||
builtScale = transform.localScale;
|
||||
|
||||
// A station, in the same sense the Draugh spawner and the Dvergar bank are: this is what
|
||||
// the troops bound to it look for to decide they are not orphans. Without it the whole
|
||||
// garrison would wither a minute after it hatched.
|
||||
RaisedThrall.RegisterStation(transform);
|
||||
|
||||
// Before the first frame is drawn, or a grown nest pops from small to large in front of
|
||||
// whoever is standing there when it loads.
|
||||
ApplyStageScale();
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
// StationStandsAt cleans destroyed transforms out of its own list, so this is belt as
|
||||
// well as braces - but a nest that is torn down should stop being a home the same frame,
|
||||
// not the next time somebody asks.
|
||||
RaisedThrall.UnregisterStation(transform);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Puts the stage on screen. Every client does this off the ZDO, so nobody has to own the
|
||||
/// nest to see it the right size - section 9.1's "la scala va sul ZDO", by derivation rather
|
||||
/// than by a second synced field.
|
||||
/// </summary>
|
||||
private void ApplyStageScale()
|
||||
{
|
||||
if (nview == null || !nview.IsValid()) return;
|
||||
|
||||
// The SCALE and not the stage is what is remembered, so that retuning the growth in the
|
||||
// .cfg moves the nests already standing instead of waiting for a stage they may never
|
||||
// buy again.
|
||||
float wanted = SvermHiveStage.ScaleOf(SvermHiveStage.Of(transform));
|
||||
if (Mathf.Approximately(wanted, shownScale)) return;
|
||||
|
||||
shownScale = wanted;
|
||||
transform.localScale = builtScale * wanted;
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
// ABOVE the owner check, and that is the point of it: the client who bought the stage is
|
||||
// not necessarily the client who owns the nest, and everyone has to see it grow.
|
||||
ApplyStageScale();
|
||||
|
||||
// Same reason, same place. The flies hang over the nest always; the green reek only
|
||||
// while there is something going down, which makes the digestion a thing you can see
|
||||
// from across the field instead of a number on a hover text.
|
||||
if (Time.time >= nextVfx)
|
||||
{
|
||||
nextVfx = Time.time + 2f;
|
||||
|
||||
float scale = SvermConfigManagement.NestVfxScale;
|
||||
SvermHiveVfx.EnsureFlies(transform, scale);
|
||||
SvermHiveVfx.SetGas(transform, SvermBiomass.Digesting(transform) > 0f, scale);
|
||||
|
||||
// The taken beehives wear the same two marks, smaller. Driven from here rather than
|
||||
// from the sweep because the sweep is the OWNER's round and these have to show up on
|
||||
// every client.
|
||||
SvermBeehive.DressInfected(transform.position);
|
||||
}
|
||||
|
||||
// Only the owner runs the colony. Every client seeing this nest would otherwise infect
|
||||
// the same beehives over and over, each writing its own answer to the same ZDO.
|
||||
if (nview == null || !nview.IsValid() || !nview.IsOwner()) return;
|
||||
|
||||
// Ahead of the sweep gate and on a clock of its own: the sweep walks a sphere of
|
||||
// colliders and can afford to wait five seconds, while a number the player is standing
|
||||
// there watching should move about as often as they can see it move. What is actually
|
||||
// digested comes from the world clock, so this interval only decides how smooth the
|
||||
// readout is, never how fast the hive works.
|
||||
if (Time.time >= nextDigest)
|
||||
{
|
||||
nextDigest = Time.time + 1f;
|
||||
SvermBiomass.Digest(transform);
|
||||
|
||||
// Eggs work themselves out from the world clock, so this only writes down what has
|
||||
// already happened - which is what keeps the number the other clients read close to
|
||||
// the truth.
|
||||
SvermBroodEggs.Settle(transform);
|
||||
}
|
||||
|
||||
// The ticks' free respawn, on its own half-minute clock: an empty paid slot grows a new
|
||||
// one, one per pass, so a wiped-out swarm trickles back rather than arriving all at once.
|
||||
if (Time.time >= nextTick)
|
||||
{
|
||||
nextTick = Time.time + SvermConfig.TickRespawnSeconds;
|
||||
SvermBlisterTick.Replace(this);
|
||||
}
|
||||
|
||||
if (Time.time < nextSweep) return;
|
||||
nextSweep = Time.time + SvermConfig.HiveAuraSweepInterval;
|
||||
|
||||
SvermBeehive.SweepAura(transform.position);
|
||||
|
||||
Haul();
|
||||
|
||||
// Haulers come out of the NEST, and only after Bonemass. The farmers are the beehives'
|
||||
// business, not the nest's - see SvermBeehive.
|
||||
if (BossProgressionManager.GetCurrentProgressionState() >= SvermConfig.HaulerUnlockState &&
|
||||
Time.time >= nextHauler &&
|
||||
SvermWorker.HasRoom(SvermWorker.Job.Hauler))
|
||||
{
|
||||
nextHauler = Time.time + SvermConfig.WorkerSpawnInterval;
|
||||
SvermWorker.Spawn(SvermWorker.Job.Hauler, transform);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The nest eats out of the chests around it, once per living hauler per sweep.
|
||||
///
|
||||
/// THE WORK MOVED HERE FROM THE WORKERS, and that is the fix rather than a shortcut. A
|
||||
/// hauler is a creature: it wanders, it picks fights, it dies, and every one of those took
|
||||
/// the whole supply chain with it - chests stayed full and the tank stayed at zero with
|
||||
/// nothing to point at. The nest never moves and is always exactly where the chests are.
|
||||
///
|
||||
/// The haulers still matter: no hauler, no hauling. They are the reason the nest can do
|
||||
/// it, and they defend the chests they feed from - which is what they were always meant to
|
||||
/// be doing. What they are no longer is a single point of failure for the economy.
|
||||
/// </summary>
|
||||
private void Haul()
|
||||
{
|
||||
int hands = SvermWorker.Count(SvermWorker.Job.Hauler);
|
||||
if (hands <= 0) return;
|
||||
|
||||
float range = SvermConfigManagement.ChestRange;
|
||||
|
||||
foreach (Container container in Object.FindObjectsOfType<Container>())
|
||||
{
|
||||
if (container == null) continue;
|
||||
if (Vector3.Distance(container.transform.position, transform.position) > range) continue;
|
||||
|
||||
Inventory inventory = container.GetInventory();
|
||||
if (inventory == null) continue;
|
||||
|
||||
foreach (ItemDrop.ItemData item in new List<ItemDrop.ItemData>(inventory.GetAllItems()))
|
||||
{
|
||||
if (item == null || item.m_shared == null) continue;
|
||||
if (!SvermBiomass.IsFuel(item)) continue;
|
||||
|
||||
float taken = SvermBiomass.Deposit(transform, item);
|
||||
if (taken <= 0f) return; // tank full: leave everything where it is
|
||||
|
||||
inventory.RemoveItem(item, 1);
|
||||
|
||||
// Container.Save is private in the shipped assembly, so the write is pushed
|
||||
// through reflection. Without it the chest empties on this client and refills
|
||||
// from the server's copy, which reads as nothing having happened.
|
||||
ZNetView cview = container.GetComponent<ZNetView>();
|
||||
if (cview != null && cview.IsValid())
|
||||
{
|
||||
HarmonyLib.Traverse.Create(container).Method("Save").GetValue();
|
||||
}
|
||||
|
||||
if (--hands <= 0) return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>How many beehives are already claimed by this nest. Used by the build gate.</summary>
|
||||
public int CountBeehives()
|
||||
{
|
||||
return SvermBeehive.CountInAura(transform.position);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue