minor bugfix and pad support
This commit is contained in:
parent
ce671e7124
commit
6e87be3c77
21 changed files with 574 additions and 85 deletions
|
|
@ -234,8 +234,11 @@ namespace RacesOfValheim
|
|||
{
|
||||
if (fermenter == null || GetContentMethod == null) return false;
|
||||
|
||||
string content = GetContentMethod.Invoke(fermenter, null) as string;
|
||||
return content == BaseName || content == SuperiorBaseName;
|
||||
// Valheim 1.0: GetContent returns the stable hash of the prefab name, not the name. The old
|
||||
// "as string" read null for every barrel and the speed-up silently stopped.
|
||||
int content = System.Convert.ToInt32(GetContentMethod.Invoke(fermenter, null));
|
||||
return content != 0
|
||||
&& (content == BaseName.GetStableHashCode() || content == SuperiorBaseName.GetStableHashCode());
|
||||
}
|
||||
|
||||
private static Player.Food MakeFood(ItemDrop drop, GameObject prefab, string prefabName)
|
||||
|
|
|
|||
|
|
@ -103,6 +103,31 @@ namespace RacesOfValheim
|
|||
/// with every instance the table raises.</summary>
|
||||
public ButlerFamily m_family = ButlerFamily.Forge;
|
||||
|
||||
/// <summary>
|
||||
/// Whether this one stands and fights instead of walking home when trouble comes. Off for the
|
||||
/// Bone Servants, which are pacifists by decision; on for the Sverm's Seeker Workers, which
|
||||
/// keep the forge AND defend the nest. See <see cref="HandsToVanilla"/>.
|
||||
/// </summary>
|
||||
public bool m_fightsBack = false;
|
||||
|
||||
/// <summary>
|
||||
/// How close to the anchor counts as home, and how far past the configured radius it works.
|
||||
/// 2.5 and 0 for a table. A Sverm nest is metres of collider that grows with its stage, so
|
||||
/// SvermWorkerBehaviour sets both to the nest's measured edge - otherwise an idle worker would
|
||||
/// spend its life walking into the trunk, and the work circle would be mostly nest.
|
||||
/// </summary>
|
||||
public float m_homeDistance = 2.5f;
|
||||
public float m_radiusBonus = 0f;
|
||||
|
||||
/// <summary>For a servant that fights back: how close an enemy has to be to stop the work, how
|
||||
/// often that is asked, and how long the fight holds after the last sign of one.</summary>
|
||||
private const float FightRange = 12f;
|
||||
private const float FightScanInterval = 1f;
|
||||
private const float FightLinger = 5f;
|
||||
|
||||
private float m_nextFightScan;
|
||||
private float m_fightUntil;
|
||||
|
||||
private ZNetView m_nview;
|
||||
private Character m_character;
|
||||
private MonsterAI m_ai;
|
||||
|
|
@ -207,13 +232,58 @@ namespace RacesOfValheim
|
|||
}
|
||||
|
||||
/// <summary>Hit by something: stop working and walk home. It never fights back - there is
|
||||
/// nothing in this class that could.</summary>
|
||||
/// nothing in this class that could. A servant that fights back ignores this: vanilla already
|
||||
/// holds the attacker as its target (MonsterAI.OnDamaged calls SetTarget, read off the IL), and
|
||||
/// <see cref="HandsToVanilla"/> gives it the tick on the next frame.</summary>
|
||||
public void NoteDamage()
|
||||
{
|
||||
if (m_fightsBack) return;
|
||||
|
||||
m_fleeUntil = Time.time + FleeSeconds;
|
||||
m_job = null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// True while vanilla's MonsterAI should have the tick instead of the work - only ever for a
|
||||
/// servant that fights back, and only on the client that runs it.
|
||||
///
|
||||
/// VANILLA DOES THE FIGHTING, this only decides when. Two things start a fight: a target the
|
||||
/// MonsterAI already holds - which covers being hit, see NoteDamage - and an enemy inside
|
||||
/// FightRange, found with BaseAI.FindClosestEnemy. That one is a static sweep of distance and
|
||||
/// IsEnemy with no line of sight (IL), which is why the range is short. Either holds the fight
|
||||
/// for FightLinger seconds, so the worker does not flicker between swinging and walking to the
|
||||
/// chest on alternate ticks.
|
||||
///
|
||||
/// The job is dropped, not the payload: whatever it was carrying stays in the ZDO, and the
|
||||
/// first plan after the fight carries it on to where it was going.
|
||||
/// </summary>
|
||||
public bool HandsToVanilla()
|
||||
{
|
||||
if (!m_fightsBack || m_ai == null || m_character == null || m_character.IsDead()) return false;
|
||||
if (m_nview == null || !m_nview.IsValid() || !m_nview.IsOwner()) return false;
|
||||
|
||||
Character target = m_ai.GetTargetCreature();
|
||||
if (target != null && !target.IsDead())
|
||||
{
|
||||
m_fightUntil = Time.time + FightLinger;
|
||||
}
|
||||
else if (Time.time >= m_nextFightScan)
|
||||
{
|
||||
m_nextFightScan = Time.time + FightScanInterval;
|
||||
if (BaseAI.FindClosestEnemy(m_character, transform.position, FightRange) != null)
|
||||
{
|
||||
m_fightUntil = Time.time + FightLinger;
|
||||
}
|
||||
}
|
||||
|
||||
if (Time.time >= m_fightUntil) return false;
|
||||
|
||||
m_job = null;
|
||||
m_nextPlan = 0f; // the fight moved it; plan afresh the moment it hands back
|
||||
SetStatus("Fighting.");
|
||||
return true;
|
||||
}
|
||||
|
||||
// ================================================================ the tick
|
||||
|
||||
/// <summary>Everything. Returns what MonsterAI.UpdateAI would have returned.</summary>
|
||||
|
|
@ -327,7 +397,7 @@ namespace RacesOfValheim
|
|||
List<Piece> pieces = AllPiecesField != null ? AllPiecesField.GetValue(null) as List<Piece> : null;
|
||||
if (pieces == null) return;
|
||||
|
||||
float radius = ButlerConfig.WorkRadius.Value;
|
||||
float radius = ButlerConfig.WorkRadius.Value + m_radiusBonus;
|
||||
float radiusSq = radius * radius;
|
||||
|
||||
for (int i = 0; i < pieces.Count; i++)
|
||||
|
|
@ -923,7 +993,7 @@ namespace RacesOfValheim
|
|||
return;
|
||||
}
|
||||
|
||||
MoveToPoint(dt, anchor.Value, 2.5f, false);
|
||||
MoveToPoint(dt, anchor.Value, m_homeDistance, false);
|
||||
}
|
||||
|
||||
// ================================================================ the ground
|
||||
|
|
@ -1356,6 +1426,10 @@ namespace RacesOfValheim
|
|||
BoneServantAI servant = __instance.GetComponent<BoneServantAI>();
|
||||
if (servant == null) return true;
|
||||
|
||||
// The one way back into vanilla: a servant that fights back hands over the whole tick for
|
||||
// as long as there is a fight. Always false for the Bone Servants themselves.
|
||||
if (servant.HandsToVanilla()) return true;
|
||||
|
||||
__result = servant.Tick(__0);
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -65,6 +65,11 @@ namespace RacesOfValheim
|
|||
/// "RPC_" prefix in this build - "RPC_AddOre", not "AddOre". A wrong name here is a silent no-op,
|
||||
/// which is exactly the class of bug that takes an evening to find, so the four names below were
|
||||
/// read out of each Awake() rather than remembered.
|
||||
///
|
||||
/// A wrong ARGUMENT LIST is not silent: Valheim 1.0 added a trailing "bool cheated" to every
|
||||
/// add-item RPC (and the Fermenter's now takes the prefab's stable hash, not its name), and the
|
||||
/// old calls threw EndOfStreamException on the receiving end, every tick. The servant's goods
|
||||
/// are real, so cheated is always false.
|
||||
/// </summary>
|
||||
public abstract class ButlerStation
|
||||
{
|
||||
|
|
@ -199,8 +204,9 @@ namespace RacesOfValheim
|
|||
public static readonly MethodInfo CookFireLit = AccessTools.Method(typeof(CookingStation), "IsFireLit");
|
||||
|
||||
public static readonly MethodInfo FermenterStatus = AccessTools.Method(typeof(Fermenter), "GetStatus");
|
||||
// 1.0 dropped the string overload: the Fermenter matches on GetStableHashCode of the name.
|
||||
public static readonly MethodInfo FermenterAllowed =
|
||||
AccessTools.Method(typeof(Fermenter), "IsItemAllowed", new[] { typeof(string) });
|
||||
AccessTools.Method(typeof(Fermenter), "IsItemAllowed", new[] { typeof(int) });
|
||||
|
||||
// CookingStation.Status and Fermenter.Status are private nested enums: they cannot be named
|
||||
// in source, so they travel as ints. Values read from the assembly, not assumed.
|
||||
|
|
@ -270,7 +276,7 @@ namespace RacesOfValheim
|
|||
public override void Add(string prefabName)
|
||||
{
|
||||
Claim();
|
||||
Nview.InvokeRPC("RPC_AddOre", prefabName);
|
||||
Nview.InvokeRPC("RPC_AddOre", prefabName, false);
|
||||
}
|
||||
|
||||
public override bool HasWork { get { return Queued > 0; } }
|
||||
|
|
@ -318,8 +324,9 @@ namespace RacesOfValheim
|
|||
get { return m_cooking.m_slots != null ? m_cooking.m_slots.Length : 0; }
|
||||
}
|
||||
|
||||
/// <summary>GetSlot hands back three values through out parameters, one of which is a
|
||||
/// private enum. Through reflection that means an args array and an int.</summary>
|
||||
/// <summary>GetSlot hands back four values through out parameters, one of which is a
|
||||
/// private enum. Through reflection that means an args array and an int. The fourth, a
|
||||
/// bool "cheated", arrived with 1.0; it is ignored, but the array must have room for it.</summary>
|
||||
private bool ReadSlot(int index, out string name, out float cooked, out int status)
|
||||
{
|
||||
name = null;
|
||||
|
|
@ -328,7 +335,7 @@ namespace RacesOfValheim
|
|||
|
||||
if (Vanilla.CookGetSlot == null) return false;
|
||||
|
||||
object[] args = new object[] { index, null, null, null };
|
||||
object[] args = new object[] { index, null, null, null, null };
|
||||
Vanilla.CookGetSlot.Invoke(m_cooking, args);
|
||||
|
||||
name = args[1] as string;
|
||||
|
|
@ -367,7 +374,7 @@ namespace RacesOfValheim
|
|||
public override void Add(string prefabName)
|
||||
{
|
||||
Claim();
|
||||
Nview.InvokeRPC("RPC_AddItem", prefabName);
|
||||
Nview.InvokeRPC("RPC_AddItem", prefabName, false);
|
||||
}
|
||||
|
||||
public override bool HasWork { get { return !Vanilla.Call(Vanilla.CookEmpty, m_cooking, true); } }
|
||||
|
|
@ -486,13 +493,14 @@ namespace RacesOfValheim
|
|||
|
||||
public override bool Accepts(string prefabName)
|
||||
{
|
||||
return Vanilla.Allowed(Vanilla.FermenterAllowed, m_fermenter, prefabName);
|
||||
if (Vanilla.FermenterAllowed == null || string.IsNullOrEmpty(prefabName)) return false;
|
||||
return (bool)Vanilla.FermenterAllowed.Invoke(m_fermenter, new object[] { prefabName.GetStableHashCode() });
|
||||
}
|
||||
|
||||
public override void Add(string prefabName)
|
||||
{
|
||||
Claim();
|
||||
Nview.InvokeRPC("RPC_AddItem", prefabName);
|
||||
Nview.InvokeRPC("RPC_AddItem", prefabName.GetStableHashCode(), false);
|
||||
}
|
||||
|
||||
public override bool HasWork { get { return Status != Vanilla.FermentEmpty; } }
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"name": "RacesOfValheim",
|
||||
"description": "A Valheim mod that adds ten custom playable races (Aswid, Draugh, Dvergar, Fenrir, Furling, Skadi, Skeleton, Sverm, Trenta, Trol) each with unique abilities, traits, race stations and a deep boss-driven progression system.",
|
||||
"version_number": "1.4.14",
|
||||
"version_number": "1.4.15",
|
||||
"website_url": "",
|
||||
"dependencies": [
|
||||
"denikson-BepInExPack_Valheim-5.4.2333",
|
||||
|
|
|
|||
|
|
@ -809,7 +809,7 @@ namespace RacesOfValheim
|
|||
|
||||
if (set == null) return;
|
||||
|
||||
if (RaceClawsConfig.ActivateKey.Value.IsDown())
|
||||
if (RaceClawsConfig.ActivateKey.Value.IsDown() || RaceInput.ConsumePress(RaceClawsConfig.ActivateKey.Value))
|
||||
{
|
||||
if (RaceInput.Allowed)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -201,10 +201,21 @@ namespace RacesOfValheim
|
|||
}
|
||||
sb.AppendLine($"Troops: {roster}They follow when you ask, walk home when you let them go, and mend themselves.\n");
|
||||
|
||||
string haulers = state >= SvermConfig.HaulerUnlockState
|
||||
? $", and up to {SvermConfigManagement.Haulers} haulers come out of the nest to carry food back into it"
|
||||
: ", and the haulers who carry food back into it will not hatch until Bonemass falls";
|
||||
sb.AppendLine($"Seeker Workers: free, and always free - no biomass, no egg, and a new one when an old one dies. Two trades that never share hands: up to {SvermConfigManagement.Farmers} farmers come out of the infected beehives to work the ground{haulers}. They are half a Seeker in size, in health and in reach, they take no orders and they never follow - they stay where they were born and defend what stands there.\n");
|
||||
string workers = state >= SvermConfig.HaulerUnlockState
|
||||
? $"up to {SvermConfigManagement.Haulers} come out of the nest"
|
||||
: "none will come out of the nest until Bonemass falls";
|
||||
|
||||
// The sigil by its in-game name, so the page says what the player actually has to put
|
||||
// in the chest rather than a prefab name.
|
||||
string sigil = ButlerConfig.SigilItem.Value;
|
||||
UnityEngine.GameObject sigilPrefab = ObjectDB.instance != null ? ObjectDB.instance.GetItemPrefab(sigil) : null;
|
||||
ItemDrop sigilDrop = sigilPrefab != null ? sigilPrefab.GetComponent<ItemDrop>() : null;
|
||||
if (sigilDrop != null && sigilDrop.m_itemData?.m_shared != null && Localization.instance != null)
|
||||
{
|
||||
sigil = Localization.instance.Localize(sigilDrop.m_itemData.m_shared.m_name);
|
||||
}
|
||||
|
||||
sb.AppendLine($"Seeker Workers: free, and always free - no biomass, no egg, and a new one when an old one dies; {workers}. While they live the nest feeds itself from the chests at its foot, and they keep the forge the way a Bone Smith does: put {sigil} in a chest within {ButlerConfig.WorkRadius.Value:0} meters of the nest's edge and they carry ore and fuel from it to the smelters, kilns and mills around, then bring what comes out back to that chest. They are half a Seeker in size, in health and in bite, they take no orders and they never follow - they fight what comes near, mend what you built, and go back to work.\n");
|
||||
|
||||
sb.AppendLine($"Blister Tick {SvermConfig.TickPrice:0}: buys a slot forever. It runs at what you are fighting and bursts, and the nest grows another one {SvermConfig.TickRespawnSeconds:0} seconds later, free.\n");
|
||||
|
||||
|
|
|
|||
|
|
@ -77,6 +77,7 @@ namespace RacesOfValheim
|
|||
/// </summary>
|
||||
public static bool IsDownIgnoringHeldKeys(this KeyboardShortcut shortcut)
|
||||
{
|
||||
if (ConsumePress(shortcut)) return true;
|
||||
if (shortcut.MainKey == KeyCode.None) return false;
|
||||
if (!Input.GetKeyDown(shortcut.MainKey)) return false;
|
||||
|
||||
|
|
@ -100,6 +101,33 @@ namespace RacesOfValheim
|
|||
return true;
|
||||
}
|
||||
|
||||
// A key press that came from somewhere other than the keyboard - the race group in the radial
|
||||
// menu (RaceRadial). Held for a short window rather than one frame, because the radial closes
|
||||
// with an animation and the race reading the key may not run on the very next frame; the
|
||||
// first matching read takes it, so it fires once.
|
||||
private const float PressWindow = 0.5f;
|
||||
private static KeyboardShortcut pressed = KeyboardShortcut.Empty;
|
||||
private static float pressedUntil = -1f;
|
||||
|
||||
public static void Press(KeyboardShortcut shortcut)
|
||||
{
|
||||
pressed = shortcut;
|
||||
pressedUntil = Time.time + PressWindow;
|
||||
}
|
||||
|
||||
/// <summary>True once if <paramref name="shortcut"/> was pressed through <see cref="Press"/>.
|
||||
/// IsDownIgnoringHeldKeys already asks; the two readers still on BepInEx's own IsDown() ask
|
||||
/// directly.</summary>
|
||||
public static bool ConsumePress(KeyboardShortcut shortcut)
|
||||
{
|
||||
if (Time.time > pressedUntil) return false;
|
||||
if (shortcut.MainKey == KeyCode.None || shortcut.MainKey != pressed.MainKey) return false;
|
||||
if (!System.Linq.Enumerable.SequenceEqual(shortcut.Modifiers, pressed.Modifiers)) return false;
|
||||
|
||||
pressedUntil = -1f;
|
||||
return true;
|
||||
}
|
||||
|
||||
// Gamepad counterparts of the three mouse buttons, indexed like Input.GetMouseButton.
|
||||
// Not a free choice: ZInput.ResetKBMButtons binds Attack to Mouse0, Block to Mouse1 and
|
||||
// SecondaryAttack to Mouse2, so each form attack lands on the pad button vanilla already
|
||||
|
|
|
|||
209
JotunnModStub/RaceRadial.cs
Normal file
209
JotunnModStub/RaceRadial.cs
Normal file
|
|
@ -0,0 +1,209 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using BepInEx.Configuration;
|
||||
using HarmonyLib;
|
||||
using UnityEngine;
|
||||
using Valheim.UI;
|
||||
using Object = UnityEngine.Object;
|
||||
|
||||
namespace RacesOfValheim
|
||||
{
|
||||
/// <summary>
|
||||
/// The race's powers on a gamepad: one more group in Valheim 1.0's radial menu, named after the
|
||||
/// player's race, with one entry per form and ability.
|
||||
///
|
||||
/// WHY THE RADIAL AND NOT A BUTTON. Read off the 1.0 assemblies with Cecil: every physical pad
|
||||
/// button is bound in all four layouts, the only chords vanilla leaves alone are LT+X and LT+R3
|
||||
/// in Classic only, and LT is already the transformed forms' Mouse1 attack through
|
||||
/// RaceInput.PadAttackButtons. The radial is opened the way vanilla opens it (hold R3, or the
|
||||
/// keyboard's own radial key), follows whatever layout is picked, and has room for every race.
|
||||
///
|
||||
/// NO RACE CODE CHANGES. An entry does not call into the race: it "presses" the key the player
|
||||
/// already has bound (RaceInput.Press), and the race's own IsDownIgnoringHeldKeys check picks it
|
||||
/// up on its next Update. Unlock rules, cooldowns and the messages that go with them therefore
|
||||
/// behave exactly as they do from the keyboard, and a rebound key is followed for free.
|
||||
///
|
||||
/// Everything vanilla-side was read, not guessed: ValheimRadialConfig.InitRadialConfig builds
|
||||
/// its top page by calling AddEmoteGroup(radial, elements) among others, a group is a
|
||||
/// GroupElement instantiated from RadialData.SO and Init'ed with (config, back, radial), and its
|
||||
/// Interact just calls radial.QueuedOpen(config, back). Leaves are elements whose Interact and
|
||||
/// CloseOnInteract are public Func<bool> setters; Name's setter is private, hence the
|
||||
/// reflection.
|
||||
/// </summary>
|
||||
public static class RaceRadial
|
||||
{
|
||||
private class Entry
|
||||
{
|
||||
public string Race;
|
||||
public string Label;
|
||||
public Func<ConfigEntry<KeyboardShortcut>> Key;
|
||||
public string Icon; // an item prefab whose icon is borrowed; may not exist
|
||||
public Func<Player, bool> Available; // null means always, for that race
|
||||
}
|
||||
|
||||
private static readonly List<Entry> Entries = new List<Entry>
|
||||
{
|
||||
new Entry { Race = "Fenrir", Label = "Wolf Form", Key = () => FenrirConfig.WolfFormKey, Icon = "TrophyWolf" },
|
||||
new Entry { Race = "Fenrir", Label = "Fenrir Form", Key = () => FenrirConfig.FenrirFormKey, Icon = "TrophyFenring" },
|
||||
new Entry { Race = "Fenrir", Label = "Cultist Form", Key = () => FenrirConfig.CultistFormKey, Icon = "TrophyCultist" },
|
||||
new Entry { Race = "Fenrir", Label = "Howl", Key = () => FenrirConfig.HowlKey, Icon = "TrophyUlv" },
|
||||
|
||||
new Entry { Race = "Aswid", Label = "Bat Form", Key = () => AswidConfig.BatFormKey, Icon = "TrophyBat" },
|
||||
new Entry { Race = "Aswid", Label = "Mist Form", Key = () => AswidConfig.MistFormKey, Icon = "TrophyWraith" },
|
||||
new Entry { Race = "Aswid", Label = "Eclipse", Key = () => AswidConfig.EclipseKey, Icon = "TrophyFader" },
|
||||
new Entry { Race = "Aswid", Label = "Tame", Key = () => AswidConfig.TameKey, Icon = "TrophyWolf" },
|
||||
new Entry { Race = "Aswid", Label = "Devour", Key = () => AswidConfig.ToggleDevourKey, Icon = "TrophyDraugr" },
|
||||
|
||||
new Entry { Race = "Skadi", Label = "Drake Form", Key = () => SkadiConfig.DrakeFormKey, Icon = "TrophyHatchling" },
|
||||
new Entry { Race = "Skadi", Label = "Moder Form", Key = () => SkadiConfig.ModerFormKey, Icon = "TrophyDragonQueen" },
|
||||
new Entry { Race = "Skadi", Label = "Fader Form", Key = () => SkadiConfig.FaderFormKey, Icon = "TrophyFader" },
|
||||
|
||||
new Entry { Race = "Trol", Label = "True Form", Key = () => TrolConfig.TrueFormKey, Icon = "TrophyFrostTroll" },
|
||||
new Entry { Race = "Trol", Label = "Throw Rock", Key = () => TrolConfig.ThrowRockKey, Icon = "Stone" },
|
||||
new Entry { Race = "Trol", Label = "Grab Log", Key = () => TrolConfig.GrabLogKey, Icon = "Wood" },
|
||||
|
||||
new Entry { Race = "Trenta", Label = "Purple Rain", Key = () => TrentaConfigManagement.PurpleRainKey, Icon = "Blueberries" },
|
||||
new Entry { Race = "Trenta", Label = "Homecoming Portal", Key = () => TrentaConfigManagement.PortalKey, Icon = "SurtlingCore" },
|
||||
new Entry { Race = "Trenta", Label = "Muspell Form", Key = () => TrentaConfigManagement.MuspellKey, Icon = "TrophySurtling" },
|
||||
|
||||
new Entry { Race = "Dvergar", Label = "Runic Ping", Key = () => DvergarConfigManagement.RunicPingKey, Icon = "TrophyDvergr" },
|
||||
new Entry { Race = "Dvergar", Label = "Runic Overcharge", Key = () => DvergarConfigManagement.RunicOverchargeKey, Icon = "Eitr" },
|
||||
|
||||
new Entry { Race = "Sverm", Label = "Ravager Strain", Key = () => SvermConfigManagement.RavagerKey, Icon = "TrophySeekerBrute" },
|
||||
|
||||
// Any race: shown to whoever RaceClawSet has claws for.
|
||||
new Entry { Race = null, Label = "Grow Claws", Key = () => RaceClawsConfig.ActivateKey, Icon = "TrophyWolf",
|
||||
Available = player => RaceClawSet.For(player) != null },
|
||||
};
|
||||
|
||||
private static readonly MethodInfo SetName = AccessTools.PropertySetter(typeof(RadialMenuElement), "Name");
|
||||
|
||||
/// <summary>Called from the AddEmoteGroup postfix: appends the race's group to vanilla's top page.</summary>
|
||||
public static void AddGroup(IRadialConfig back, RadialBase radial, List<RadialMenuElement> elements)
|
||||
{
|
||||
Player player = Player.m_localPlayer;
|
||||
if (player == null || radial == null || elements == null) return;
|
||||
if (RadialData.SO == null || RadialData.SO.GroupElement == null) return;
|
||||
|
||||
string race = RaceOf(player);
|
||||
List<Entry> mine = For(player, race);
|
||||
if (mine.Count == 0) return;
|
||||
|
||||
GroupElement group = Object.Instantiate(RadialData.SO.GroupElement);
|
||||
group.Init(new RaceRadialConfig(race, mine), back, radial);
|
||||
elements.Add(group);
|
||||
}
|
||||
|
||||
private static List<Entry> For(Player player, string race)
|
||||
{
|
||||
List<Entry> mine = new List<Entry>();
|
||||
foreach (Entry entry in Entries)
|
||||
{
|
||||
if (entry.Race != null && entry.Race != race) continue;
|
||||
if (entry.Available != null && !entry.Available(player)) continue;
|
||||
if (entry.Key() == null) continue; // that race's config never bound: nothing to press
|
||||
mine.Add(entry);
|
||||
}
|
||||
return mine;
|
||||
}
|
||||
|
||||
/// <summary>The same two sources RaceClaws.GetRace reads, in the same order, "Human" in the
|
||||
/// ZDO counting as no answer.</summary>
|
||||
private static string RaceOf(Player player)
|
||||
{
|
||||
ZNetView nview = player.GetComponent<ZNetView>();
|
||||
if (nview != null && nview.IsValid())
|
||||
{
|
||||
string race = nview.GetZDO().GetString("RacesOfValheim_Race", "");
|
||||
if (!string.IsNullOrEmpty(race) && race != "Human") return race;
|
||||
}
|
||||
|
||||
if (player.m_customData != null && player.m_customData.TryGetValue("Race", out string custom))
|
||||
{
|
||||
return custom;
|
||||
}
|
||||
|
||||
return "Human";
|
||||
}
|
||||
|
||||
/// <summary>An item's inventory icon, or null - a missing prefab only costs the picture.</summary>
|
||||
private static Sprite IconOf(string prefabName)
|
||||
{
|
||||
if (ObjectDB.instance == null || string.IsNullOrEmpty(prefabName)) return null;
|
||||
|
||||
GameObject prefab = ObjectDB.instance.GetItemPrefab(prefabName);
|
||||
ItemDrop drop = prefab != null ? prefab.GetComponent<ItemDrop>() : null;
|
||||
if (drop == null || drop.m_itemData?.m_shared?.m_icons == null || drop.m_itemData.m_shared.m_icons.Length == 0) return null;
|
||||
|
||||
return drop.m_itemData.GetIcon();
|
||||
}
|
||||
|
||||
/// <summary>The group's own page: one leaf per entry, built fresh every time it is opened so a
|
||||
/// rebound key or a newly grown claw set is always current.</summary>
|
||||
private class RaceRadialConfig : IRadialConfig
|
||||
{
|
||||
private readonly string m_race;
|
||||
private readonly List<Entry> m_entries;
|
||||
|
||||
public RaceRadialConfig(string race, List<Entry> entries)
|
||||
{
|
||||
m_race = race;
|
||||
m_entries = entries;
|
||||
}
|
||||
|
||||
public string LocalizedName => m_race;
|
||||
|
||||
public Sprite Sprite => m_entries.Count > 0 ? IconOf(m_entries[0].Icon) : null;
|
||||
|
||||
public void InitRadialConfig(RadialBase radial)
|
||||
{
|
||||
List<RadialMenuElement> leaves = new List<RadialMenuElement>();
|
||||
|
||||
foreach (Entry entry in m_entries)
|
||||
{
|
||||
RadialMenuElement leaf = Object.Instantiate(RadialData.SO.EmoteElement);
|
||||
Entry captured = entry;
|
||||
|
||||
string key = entry.Key().Value.ToString();
|
||||
SetName?.Invoke(leaf, new object[] { string.IsNullOrEmpty(key) ? entry.Label : $"{entry.Label} ({key})" });
|
||||
|
||||
leaf.Interact = () =>
|
||||
{
|
||||
RaceInput.Press(captured.Key().Value);
|
||||
return true;
|
||||
};
|
||||
leaf.CloseOnInteract = () => true;
|
||||
|
||||
Sprite icon = IconOf(entry.Icon);
|
||||
if (leaf.Icon != null)
|
||||
{
|
||||
leaf.Icon.gameObject.SetActive(icon != null);
|
||||
leaf.Icon.sprite = icon;
|
||||
}
|
||||
|
||||
leaves.Add(leaf);
|
||||
}
|
||||
|
||||
radial.ConstructRadial(leaves);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[HarmonyPatch(typeof(ValheimRadialConfig), "AddEmoteGroup")]
|
||||
public static class RaceRadial_AddEmoteGroup_Patch
|
||||
{
|
||||
// Wrapped: a mistake here must cost the race group, never the player's whole radial menu.
|
||||
public static void Postfix(ValheimRadialConfig __instance, RadialBase radial, List<RadialMenuElement> elements)
|
||||
{
|
||||
try
|
||||
{
|
||||
RaceRadial.AddGroup(__instance, radial, elements);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Jotunn.Logger.LogWarning($"[RaceRadial] Could not add the race group to the radial menu: {e}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -15,7 +15,7 @@ namespace RacesOfValheim
|
|||
{
|
||||
public const string PluginGUID = "com.nandor.racesofvalheim";
|
||||
public const string PluginName = "Races Of Valheim";
|
||||
public const string PluginVersion = "1.4.14";
|
||||
public const string PluginVersion = "1.4.15";
|
||||
|
||||
private readonly Harmony harmony = new Harmony(PluginGUID);
|
||||
|
||||
|
|
|
|||
|
|
@ -313,6 +313,15 @@ namespace RacesOfValheim
|
|||
return false;
|
||||
}
|
||||
|
||||
// THE PATROL POINT GOES OFF while it follows, and GoHome puts it back when it is let go.
|
||||
// MonsterAI.UpdateTarget measures a tame creature's target from its patrol point whenever
|
||||
// it has one, and only falls back to the follow target when it has none (IL). Left on, a
|
||||
// thrall walking beside its master kept judging every enemy by its distance from the
|
||||
// STATION - so the further from home, the fewer fights it would take. ResetPatrolPoint
|
||||
// writes the ZDO as well as the field, which matters: GetPatrolPoint re-reads the ZDO
|
||||
// every second and would switch it straight back on.
|
||||
if (m_ai != null) m_ai.ResetPatrolPoint();
|
||||
|
||||
m_monsterAI.SetFollowTarget(player.gameObject);
|
||||
if (announce) player.Message(MessageHud.MessageType.Center, $"{m_character.m_name} follows.");
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -131,8 +131,13 @@ namespace RacesOfValheim
|
|||
{
|
||||
if (Player.m_localPlayer == null || Player.m_localPlayer.IsDead()) return;
|
||||
|
||||
// Handle Flight Toggle (Right Mouse by default, rebindable) - Disabled for Fader
|
||||
if (RaceInput.Allowed && SkadiConfig.FlightToggleKey.Value.IsDownIgnoringHeldKeys() && formRules != null && formRules.Form != SkadiProgression.FormType.SkeletonDragon)
|
||||
// Handle Flight Toggle (Right Mouse by default, rebindable) - Disabled for Fader.
|
||||
// On a pad it is the Block button, Right Mouse's vanilla partner (RaceInput.PadAttackDown(1)):
|
||||
// the left trigger in the Classic layout. Free here - neither drake nor Moder has a
|
||||
// button-1 attack; the only one is Fader's spin, and Fader never flies.
|
||||
if (RaceInput.Allowed &&
|
||||
(SkadiConfig.FlightToggleKey.Value.IsDownIgnoringHeldKeys() || RaceInput.PadAttackDown(1)) &&
|
||||
formRules != null && formRules.Form != SkadiProgression.FormType.SkeletonDragon)
|
||||
{
|
||||
if (!isFlying && !isLanding)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -305,6 +305,8 @@ namespace RacesOfValheim
|
|||
// How much of the aim heading survives the climb out of water. Mostly up, with enough
|
||||
// forward in it that the player still chooses which shore they surface towards.
|
||||
private const float LIFTOFF_HEADING_BLEND = 0.35f;
|
||||
// How far the left stick has to be pushed before it counts as W or S.
|
||||
private const float StickThreshold = 0.5f;
|
||||
|
||||
/// <summary>
|
||||
/// True while the local player is beating backwards this frame. Read by
|
||||
|
|
@ -326,10 +328,17 @@ namespace RacesOfValheim
|
|||
var traverse = Traverse.Create(__instance);
|
||||
Vector3 lookDir = Player.m_localPlayer.GetLookDir();
|
||||
bool input = RaceInput.Allowed;
|
||||
bool forward = input && Input.GetKey(KeyCode.W);
|
||||
// The pad's half of W/S: the left stick, read with vanilla's own sign -
|
||||
// PlayerController.FixedUpdate takes forward as the NEGATED GetJoyLeftStickY.
|
||||
// Flight only knows powered forward, reverse or neither, so the stick is a
|
||||
// threshold, not a throttle. Steering stays on the camera, i.e. the right stick.
|
||||
float stick = -ZInput.GetJoyLeftStickY();
|
||||
bool forward = input && (Input.GetKey(KeyCode.W) || stick > StickThreshold);
|
||||
// Forward wins a W+S mash rather than the two cancelling into a dead hover.
|
||||
bool backward = input && !forward && Input.GetKey(KeyCode.S);
|
||||
bool sprintKey = input && (Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift));
|
||||
bool backward = input && !forward && (Input.GetKey(KeyCode.S) || stick < -StickThreshold);
|
||||
// Sprint on a pad is vanilla's run button, wherever the chosen layout puts it.
|
||||
bool sprintKey = input && (Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift) ||
|
||||
ZInput.GetButton("JoyRun"));
|
||||
bool onGround = __instance.IsOnGround();
|
||||
// IsSwimming is the exact test UpdateMotion uses to hand the frame to UpdateSwimming
|
||||
// instead of UpdateFlying, so it is also the one condition SkadiWaterFlightPatch has
|
||||
|
|
|
|||
|
|
@ -57,6 +57,15 @@ namespace RacesOfValheim
|
|||
BaseAI ai = prefab.GetComponent<BaseAI>();
|
||||
if (ai != null) ai.m_randomMoveRange = SvermConfig.TroopLeashRange;
|
||||
|
||||
// The same fighting bounds as the rest of the swarm - SvermConfig.TroopAlertRange. A tick
|
||||
// with the vanilla numbers ran off after anything in sight and burst far from home.
|
||||
MonsterAI monster = prefab.GetComponent<MonsterAI>();
|
||||
if (monster != null)
|
||||
{
|
||||
monster.m_alertRange = SvermConfig.TroopAlertRange;
|
||||
monster.m_maxChaseDistance = SvermConfig.TroopAlertRange;
|
||||
}
|
||||
|
||||
// Nothing to farm off something that respawns for free forever. This one matters more
|
||||
// than on the other troops for exactly that reason.
|
||||
foreach (CharacterDrop drops in prefab.GetComponentsInChildren<CharacterDrop>(true))
|
||||
|
|
|
|||
|
|
@ -98,6 +98,15 @@ namespace RacesOfValheim
|
|||
BaseAI ai = prefab.GetComponent<BaseAI>();
|
||||
if (ai != null) ai.m_randomMoveRange = SvermConfig.TroopLeashRange;
|
||||
|
||||
// The hive's own bounds for a fight - see SvermConfig.TroopAlertRange. Without these the
|
||||
// troops kept the vanilla prefab's numbers and chased whatever they could see.
|
||||
MonsterAI monster = prefab.GetComponent<MonsterAI>();
|
||||
if (monster != null)
|
||||
{
|
||||
monster.m_alertRange = SvermConfig.TroopAlertRange;
|
||||
monster.m_maxChaseDistance = SvermConfig.TroopAlertRange;
|
||||
}
|
||||
|
||||
foreach (CharacterDrop drops in prefab.GetComponentsInChildren<CharacterDrop>(true))
|
||||
{
|
||||
if (drops != null) Object.DestroyImmediate(drops);
|
||||
|
|
@ -191,7 +200,10 @@ namespace RacesOfValheim
|
|||
/// creature on the TERRAIN height there, so a nest on a slope does not bury anyone either.
|
||||
/// The per-kind height goes on top, which is what keeps the Gjall in the air.
|
||||
/// </summary>
|
||||
private static Vector3 SpawnSpot(SvermHiveBehaviour hive, Kind kind)
|
||||
private static Vector3 SpawnSpot(SvermHiveBehaviour hive, Kind kind) => SpawnSpot(hive, kind.SpawnHeight);
|
||||
|
||||
/// <summary>The same ring, for anything else the nest puts on the ground - the workers.</summary>
|
||||
internal static Vector3 SpawnSpot(SvermHiveBehaviour hive, float height)
|
||||
{
|
||||
Vector3 centre = hive.transform.position;
|
||||
float radius = RingRadius(hive);
|
||||
|
|
@ -206,14 +218,14 @@ namespace RacesOfValheim
|
|||
|
||||
if (Physics.CheckSphere(candidate + Vector3.up * 1.5f, 1f, obstacleMask)) continue;
|
||||
|
||||
return candidate + Vector3.up * kind.SpawnHeight;
|
||||
return candidate + Vector3.up * height;
|
||||
}
|
||||
|
||||
// Twelve tries and everything is built up: due south on the ring anyway. Still outside
|
||||
// the nest, which is the thing this is here to guarantee.
|
||||
Vector3 fallback = centre + new Vector3(0f, 0f, -radius);
|
||||
if (ZoneSystem.instance != null) fallback.y = ZoneSystem.instance.GetGroundHeight(fallback);
|
||||
return fallback + Vector3.up * kind.SpawnHeight;
|
||||
return fallback + Vector3.up * height;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -224,7 +236,7 @@ namespace RacesOfValheim
|
|||
/// small one hatches troops inside the big one. Only solid meshes are measured; the hive's
|
||||
/// particle effects have bounds of their own and would report a ring the size of a field.
|
||||
/// </summary>
|
||||
private static float RingRadius(SvermHiveBehaviour hive)
|
||||
internal static float RingRadius(SvermHiveBehaviour hive)
|
||||
{
|
||||
Vector3 centre = hive.transform.position;
|
||||
float widest = 0f;
|
||||
|
|
|
|||
|
|
@ -444,15 +444,12 @@ namespace RacesOfValheim
|
|||
public static readonly float WorkerHealthFraction = 0.5f;
|
||||
public static readonly float WorkerDamageFraction = 0.5f;
|
||||
|
||||
/// <summary>One out of every infected beehive on this timer, until the pool is full.</summary>
|
||||
/// <summary>One out of the nest on this timer, until the pool is full.</summary>
|
||||
public static readonly float WorkerSpawnInterval = 120f;
|
||||
|
||||
/// <summary>Haulers only start after Bonemass.</summary>
|
||||
public const int HaulerUnlockState = 4;
|
||||
|
||||
/// <summary>Ten metres. Also the radius it keeps in repair.</summary>
|
||||
public static readonly float WorkerLeashRange = 10f;
|
||||
|
||||
/// <summary>How far a worker reaches to mend, and how often it mends one thing.</summary>
|
||||
public static readonly float WorkerRepairRange = 10f;
|
||||
public static readonly float WorkerRepairInterval = 5f;
|
||||
|
|
@ -509,6 +506,18 @@ namespace RacesOfValheim
|
|||
/// <summary>How far a troop wanders from the nest when nobody is leading it.</summary>
|
||||
public static readonly float TroopLeashRange = 12f;
|
||||
|
||||
/// <summary>
|
||||
/// How far from home a troop will fight: the leash on the TARGET, not on the walk.
|
||||
///
|
||||
/// Set on the prefab as both m_alertRange and m_maxChaseDistance, and it has to be. Vanilla
|
||||
/// drops a tame creature's target once the target is further than m_alertRange from its
|
||||
/// patrol point (the nest, pinned by RaisedThrall) - read off MonsterAI.UpdateTarget - and the
|
||||
/// troops used to inherit whatever the Seeker, Gjall and Tick prefabs carry, which is 9999 in
|
||||
/// code. They hunted anything they could see. While a troop FOLLOWS, the patrol point is off
|
||||
/// and the same range is measured from the player instead.
|
||||
/// </summary>
|
||||
public static readonly float TroopAlertRange = 25f;
|
||||
|
||||
/// <summary>How long a troop outlives the nest that hatched it, in seconds.</summary>
|
||||
public static readonly float TroopWitherSeconds = 60f;
|
||||
|
||||
|
|
|
|||
|
|
@ -464,6 +464,7 @@ namespace RacesOfValheim
|
|||
return $"{SvermHiveStage.NameOf(SvermHiveStage.Of(transform))}\n" +
|
||||
SvermHiveReadout.Tank(transform) +
|
||||
$"Beehives {infected} taken of {SvermConfigManagement.Beehives} allowed, {beehives} in range\n" +
|
||||
SvermWorker.Readout(transform.position) +
|
||||
"[<color=yellow><b>$KEY_Use</b></color>] Feed it a stack";
|
||||
}
|
||||
|
||||
|
|
@ -591,8 +592,8 @@ namespace RacesOfValheim
|
|||
|
||||
Haul();
|
||||
|
||||
// Haulers come out of the NEST, and only after Bonemass. The farmers are the beehives'
|
||||
// business, not the nest's - see SvermBeehive.
|
||||
// Workers come out of the NEST, and only after Bonemass. There is no second pool: the
|
||||
// farmers section 19.3 wanted out of the beehives were dropped with the farming.
|
||||
if (BossProgressionManager.GetCurrentProgressionState() >= SvermConfig.HaulerUnlockState &&
|
||||
Time.time >= nextHauler &&
|
||||
SvermWorker.HasRoom(SvermWorker.Job.Hauler))
|
||||
|
|
|
|||
|
|
@ -112,6 +112,14 @@ namespace RacesOfValheim
|
|||
|
||||
Character attacker = hit.GetAttacker();
|
||||
|
||||
// ── Seeker Workers bite at half a Seeker's weight. Scaled on the blow and not on the
|
||||
// weapon, because the blow comes from the Seeker's default weapon and that weapon's
|
||||
// shared data is every Seeker's in the world.
|
||||
if (attacker != null && SvermWorker.IsWorker(attacker))
|
||||
{
|
||||
hit.m_damage.Modify(SvermConfig.WorkerDamageFraction);
|
||||
}
|
||||
|
||||
// ── Outgoing
|
||||
if (attacker is Player attackingPlayer && SvermVisuals.IsSvermPlayer(attackingPlayer))
|
||||
{
|
||||
|
|
|
|||
|
|
@ -147,7 +147,8 @@ namespace RacesOfValheim
|
|||
// way out, same as death or losing the race.
|
||||
if (IsActive) return;
|
||||
|
||||
if (!SvermConfigManagement.RavagerKey.Value.IsDown()) return;
|
||||
if (!SvermConfigManagement.RavagerKey.Value.IsDown() &&
|
||||
!RaceInput.ConsumePress(SvermConfigManagement.RavagerKey.Value)) return;
|
||||
if (!SvermVisuals.IsSvermPlayer(player)) return;
|
||||
|
||||
if (!SvermProgression.Current.RavagerForm)
|
||||
|
|
@ -559,7 +560,8 @@ namespace RacesOfValheim
|
|||
{
|
||||
StartCoroutine(AttackRoutine(SvermRavagerAttacks.Slam, 1.2f, 0.4f, 1.0f));
|
||||
}
|
||||
else if (SvermConfigManagement.RavagerKey.Value.IsDown() && Time.time >= nextTauntAt)
|
||||
else if ((SvermConfigManagement.RavagerKey.Value.IsDown() ||
|
||||
RaceInput.ConsumePress(SvermConfigManagement.RavagerKey.Value)) && Time.time >= nextTauntAt)
|
||||
{
|
||||
nextTauntAt = Time.time + SvermConfig.RavagerTauntCooldownSeconds;
|
||||
StartCoroutine(TauntRoutine());
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using Jotunn.Managers;
|
||||
using UnityEngine;
|
||||
|
||||
|
|
@ -8,18 +9,21 @@ namespace RacesOfValheim
|
|||
/// The Seeker Worker: half a Seeker, and the reason the colony feels like a colony rather than
|
||||
/// like a barracks.
|
||||
///
|
||||
/// TWO JOBS, TWO POOLS, and the pools do not share. Farmers come out of the infected beehives
|
||||
/// and work the ground; haulers come out of the nest after Bonemass and carry food into it.
|
||||
/// Nine alive at most between them, and neither trade can starve the other of hands - which is
|
||||
/// the whole reason they are counted separately instead of out of one number.
|
||||
/// ONE TRADE. They come out of the nest after Bonemass, up to the hauler cap, and they earn their
|
||||
/// keep twice over: the nest eats out of the chests at its foot once per living worker (see
|
||||
/// SvermHiveBehaviour.Haul), and the workers themselves keep the forge the way the Skeleton's
|
||||
/// Bone Smith does - the same brain, the same sigil chests, the same stations. Section 19.3's
|
||||
/// farmers were the other trade; farming was tried and rejected, and nothing ever spawned one.
|
||||
/// The Job enum keeps the name only so the cap entries in players' .cfg files still mean what
|
||||
/// they say.
|
||||
///
|
||||
/// They are FREE. No biomass, no egg, and they are replaced when they die. That is deliberate:
|
||||
/// they are labour, not army. Nothing they do competes with Brood, Seeker, Soldier or Gjall for
|
||||
/// the tank, and nothing about them is commandable - they stay where they were born, defend
|
||||
/// what is there, and never follow.
|
||||
/// the tank, and nothing about them is commandable - they work, they fight what comes near, and
|
||||
/// they never follow.
|
||||
///
|
||||
/// Half size, half health, half damage. The size and health are set on the prefab; the damage
|
||||
/// is halved in the damage patch, because a creature's blow comes from its default weapon and
|
||||
/// is halved in Sverm_Damage_Patch, because a creature's blow comes from its default weapon and
|
||||
/// that weapon's shared data belongs to every Seeker in the world.
|
||||
/// </summary>
|
||||
public static class SvermWorker
|
||||
|
|
@ -68,8 +72,22 @@ namespace RacesOfValheim
|
|||
CharacterDrop drop = prefab.GetComponent<CharacterDrop>();
|
||||
if (drop != null) Object.DestroyImmediate(drop);
|
||||
|
||||
BaseAI ai = prefab.GetComponent<BaseAI>();
|
||||
if (ai != null)
|
||||
{
|
||||
ai.m_avoidFire = false; // it works next to kilns for a living
|
||||
ai.m_afraidOfFire = false;
|
||||
}
|
||||
|
||||
prefab.AddComponent<SvermWorkerBehaviour>();
|
||||
|
||||
// The Bone Smith's brain, whole: the Forge family of stations, fed from chests that hold
|
||||
// the sigil. It takes the MonsterAI tick over completely, so the worker only ever swings at
|
||||
// anything because m_fightsBack hands the tick back to vanilla while there is a fight.
|
||||
BoneServantAI smith = prefab.AddComponent<BoneServantAI>();
|
||||
smith.m_family = ButlerFamily.Forge;
|
||||
smith.m_fightsBack = true;
|
||||
|
||||
PrefabManager.Instance.AddPrefab(prefab);
|
||||
Jotunn.Logger.LogInfo($"[Sverm] Registered '{PrefabName}' at {SvermConfig.WorkerScale:P0} of a Seeker.");
|
||||
}
|
||||
|
|
@ -99,11 +117,18 @@ namespace RacesOfValheim
|
|||
|
||||
public static bool HasRoom(Job job) => CountLive(job) < Cap(job);
|
||||
|
||||
/// <summary>Puts a worker on the roll. Idempotent - Spawn and the worker's own Awake both
|
||||
/// call it, and a worker loaded back from the save only ever gets the second.</summary>
|
||||
internal static void Track(SvermWorkerBehaviour worker)
|
||||
{
|
||||
if (worker != null && !live.Contains(worker)) live.Add(worker);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Puts one worker on the ground and ties it to whatever produced it.
|
||||
/// Puts one worker on the ground, bound to the nest that produced it.
|
||||
///
|
||||
/// The anchor is not decoration: it is where the worker idles, what it defends, and the
|
||||
/// centre of the three metres it searches for chests. A worker with no anchor has no job.
|
||||
/// The binding lives in the worker's own ZDO, written by the smith's brain: it is the centre
|
||||
/// of the work circle, where the worker goes when idle, and what its wither clock asks after.
|
||||
/// </summary>
|
||||
public static void Spawn(Job job, Transform anchor)
|
||||
{
|
||||
|
|
@ -112,50 +137,87 @@ namespace RacesOfValheim
|
|||
GameObject prefab = ZNetScene.instance != null ? ZNetScene.instance.GetPrefab(PrefabName) : null;
|
||||
if (prefab == null) return;
|
||||
|
||||
Vector3 where = anchor.position + Vector3.up * 0.5f + Random.insideUnitSphere * 0.5f;
|
||||
where.y = anchor.position.y + 0.5f;
|
||||
// Outside the nest, on the ring the troops hatch on. Put down at the nest's own centre a
|
||||
// worker comes out wedged in several metres of collider - fatal for a creature whose whole
|
||||
// job is walking to a furnace.
|
||||
SvermHiveBehaviour hive = anchor.GetComponent<SvermHiveBehaviour>();
|
||||
Vector3 where = hive != null ? SvermBrood.SpawnSpot(hive, 0.5f) : anchor.position + Vector3.up * 0.5f;
|
||||
|
||||
GameObject spawned = Object.Instantiate(prefab, where, Quaternion.identity);
|
||||
GameObject spawned = Object.Instantiate(prefab, where, Quaternion.Euler(0f, Random.Range(0f, 360f), 0f));
|
||||
if (spawned == null) return;
|
||||
|
||||
Character character = spawned.GetComponent<Character>();
|
||||
if (character != null) character.SetTamed(true);
|
||||
BoneServantAI smith = spawned.GetComponent<BoneServantAI>();
|
||||
if (smith != null)
|
||||
{
|
||||
smith.Bind(anchor.position); // tames it, too
|
||||
}
|
||||
else
|
||||
{
|
||||
Character character = spawned.GetComponent<Character>();
|
||||
if (character != null) character.SetTamed(true);
|
||||
}
|
||||
|
||||
SvermWorkerBehaviour behaviour = spawned.GetComponent<SvermWorkerBehaviour>()
|
||||
?? spawned.AddComponent<SvermWorkerBehaviour>();
|
||||
behaviour.Trade = job;
|
||||
behaviour.Anchor = anchor;
|
||||
|
||||
live.Add(behaviour);
|
||||
Track(behaviour);
|
||||
}
|
||||
|
||||
public static bool IsWorker(Character character)
|
||||
{
|
||||
return character != null && character.GetComponent<SvermWorkerBehaviour>() != null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// One line per worker bound to this nest, for the nest's hover.
|
||||
///
|
||||
/// The smith's brain writes what it is doing into the worker's ZDO, and the Bone Smith shows it
|
||||
/// on its table - the one feedback channel that feature has. A worker's table is the nest, so
|
||||
/// this is the same channel. Read on every client: the roll is filled by Awake, which runs
|
||||
/// everywhere, and the status comes off the ZDO.
|
||||
/// </summary>
|
||||
public static string Readout(Vector3 nest)
|
||||
{
|
||||
StringBuilder text = new StringBuilder();
|
||||
|
||||
foreach (SvermWorkerBehaviour worker in live)
|
||||
{
|
||||
if (worker == null || worker.Dead) continue;
|
||||
|
||||
BoneServantAI smith = worker.GetComponent<BoneServantAI>();
|
||||
if (smith == null || !smith.IsBoundTo(nest)) continue;
|
||||
|
||||
string status = smith.Status;
|
||||
text.Append("Worker: ").Append(string.IsNullOrEmpty(status) ? "Waiting." : status).Append('\n');
|
||||
}
|
||||
|
||||
return text.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// One worker's whole life: stay home, mend what the player built, and fight what comes.
|
||||
/// What a worker does on top of the smith's brain: keep what the player built in repair, keep
|
||||
/// its orders its own, and tell the brain how big home is.
|
||||
///
|
||||
/// THIS IS THE THIRD DESIGN AND THE FIRST HONEST ONE. The first two hung the colony's economy
|
||||
/// on a creature that walks: workers carried food from chests to the hive, and every time one
|
||||
/// wandered off or got killed the supply chain went with it - chests full, tank at zero, and
|
||||
/// nothing in the log to blame. Hauling belongs to something that cannot walk away, and
|
||||
/// feeding the hive is now the player's own job through the shop.
|
||||
///
|
||||
/// What is left is what a creature is actually good at: being somewhere, keeping it in repair,
|
||||
/// and defending it. No carrying, no farming, no orders.
|
||||
/// No farming and no orders. The carrying is the Bone Smith's and lives in BoneServantAI - the
|
||||
/// earlier hauling that hung the colony's economy on a walking creature is still gone: the nest
|
||||
/// feeds itself from its own chests, and a dead worker only ever costs the forge a trip.
|
||||
/// </summary>
|
||||
public class SvermWorkerBehaviour : MonoBehaviour
|
||||
{
|
||||
public SvermWorker.Job Trade;
|
||||
public Transform Anchor;
|
||||
/// <summary>Hauler by default, and the default matters: a worker loaded back from the save
|
||||
/// never goes through Spawn, so this is the trade it is counted under.</summary>
|
||||
public SvermWorker.Job Trade = SvermWorker.Job.Hauler;
|
||||
|
||||
public bool Dead => m_character == null || m_character.IsDead();
|
||||
|
||||
/// <summary>How far a worker that has no nest on its ZDO looks for one to adopt.</summary>
|
||||
private const float AdoptRange = 40f;
|
||||
|
||||
private Character m_character;
|
||||
private MonsterAI m_ai;
|
||||
private ZNetView m_nview;
|
||||
private BoneServantAI m_smith;
|
||||
private float m_nextHomeCheck;
|
||||
private float m_nextRepair;
|
||||
|
||||
|
|
@ -163,13 +225,28 @@ namespace RacesOfValheim
|
|||
{
|
||||
m_character = GetComponent<Character>();
|
||||
m_ai = GetComponent<MonsterAI>();
|
||||
m_nview = GetComponent<ZNetView>();
|
||||
m_smith = GetComponent<BoneServantAI>();
|
||||
|
||||
// Counted from the moment it exists, not from the moment it was spawned. The roll used to
|
||||
// be kept by Spawn alone, so every worker that came back from the save was invisible to it
|
||||
// and the nest hatched a fresh one on top, two minutes at a time, reload after reload.
|
||||
SvermWorker.Track(this);
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (Dead || Anchor == null) return;
|
||||
if (Dead) return;
|
||||
|
||||
KeepHome();
|
||||
// The owner's round only, like the smith's brain it sits beside: two clients repairing and
|
||||
// rebinding the same worker is two answers to one question.
|
||||
if (m_nview == null || !m_nview.IsValid() || !m_nview.IsOwner()) return;
|
||||
|
||||
if (Time.time >= m_nextHomeCheck)
|
||||
{
|
||||
m_nextHomeCheck = Time.time + 2f;
|
||||
KeepHome();
|
||||
}
|
||||
|
||||
if (Time.time < m_nextRepair) return;
|
||||
m_nextRepair = Time.time + SvermConfig.WorkerRepairInterval;
|
||||
|
|
@ -178,30 +255,33 @@ namespace RacesOfValheim
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ten metres, and told to the AI rather than forced on the transform.
|
||||
/// The three things the smith's brain cannot know about a nest.
|
||||
///
|
||||
/// Writing transform.position does not hold a Valheim Character - a Rigidbody and a
|
||||
/// ZSyncTransform both overwrite it on the next frame, which is why the earlier leash did
|
||||
/// nothing at all and the workers kept wandering off to die. A patrol point is the game's
|
||||
/// own way of saying "this is where you live": the AI walks back on its own pathfinding.
|
||||
/// Orders: none, from anyone. The brain never follows, but vanilla holds the tick during a
|
||||
/// fight, and an Aswid's Dominate writes a follow target straight into it.
|
||||
///
|
||||
/// SetPatrolPoint takes no argument and posts the creature where it currently STANDS, so
|
||||
/// it is put in place first. That raw write does not survive the frame, but it survives
|
||||
/// long enough for this one call to read it - and the patrol point is what holds afterwards.
|
||||
/// A home: a worker with nothing on its ZDO - hatched before the workers had this brain -
|
||||
/// adopts the nearest nest, or it would stand where it is forever with an empty circle.
|
||||
///
|
||||
/// Its size: re-measured every round, because the nest grows with its stage.
|
||||
/// </summary>
|
||||
private void KeepHome()
|
||||
{
|
||||
if (m_ai == null || Time.time < m_nextHomeCheck) return;
|
||||
m_nextHomeCheck = Time.time + 2f;
|
||||
if (m_ai != null && m_ai.GetFollowTarget() != null) m_ai.SetFollowTarget(null);
|
||||
|
||||
if (m_ai.GetFollowTarget() != null) m_ai.SetFollowTarget(null);
|
||||
if (m_smith == null) return;
|
||||
|
||||
if (Vector3.Distance(transform.position, Anchor.position) > SvermConfig.WorkerLeashRange)
|
||||
{
|
||||
transform.position = Anchor.position + Vector3.up * 0.5f;
|
||||
}
|
||||
Vector3? anchor = m_smith.Anchor;
|
||||
SvermHiveBehaviour nest = anchor != null
|
||||
? SvermHive.NearestNest(anchor.Value, 1f)
|
||||
: SvermHive.NearestNest(transform.position, AdoptRange);
|
||||
if (nest == null) return;
|
||||
|
||||
m_ai.SetPatrolPoint();
|
||||
if (anchor == null) m_smith.Bind(nest.transform.position);
|
||||
|
||||
float edge = SvermBrood.RingRadius(nest);
|
||||
m_smith.m_homeDistance = edge;
|
||||
m_smith.m_radiusBonus = edge;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue