warvulture
This commit is contained in:
parent
8580d65a56
commit
0aa1dc4dc8
19 changed files with 2432 additions and 24 deletions
292
JotunnModStub/Butler/BoneServant.cs
Normal file
292
JotunnModStub/Butler/BoneServant.cs
Normal file
|
|
@ -0,0 +1,292 @@
|
||||||
|
using HarmonyLib;
|
||||||
|
using Jotunn.Configs;
|
||||||
|
using Jotunn.Entities;
|
||||||
|
using Jotunn.Managers;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace RacesOfValheim
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The two Bone Servants and their tables. Servants that work the stations around them and never
|
||||||
|
/// lift a hand against anything.
|
||||||
|
///
|
||||||
|
/// TWO TRADES, and that was the first thing the working version asked for. One servant serving a
|
||||||
|
/// whole yard spends its life walking: with the kitchen at one edge of the circle and the furnaces
|
||||||
|
/// at the other, travel eats the margin that keeps food off the fire. So there is a SMITH for the
|
||||||
|
/// Smelter family and a COOK for cooking stations and mead, each with its own table, each with its
|
||||||
|
/// own twenty-metre circle - and the two circles may sit on top of each other, because the servants
|
||||||
|
/// never look at the same station. PieceDensityLimit counts by prefab name, so "no second table
|
||||||
|
/// within forty metres" keeps smith away from smith and cook away from cook, and needed no change
|
||||||
|
/// at all to let a smith and a cook stand side by side.
|
||||||
|
///
|
||||||
|
/// The smith keeps the ORIGINAL prefab names, BoneServant and ServantTable. That is not tidiness -
|
||||||
|
/// it means a table already standing in a test world keeps working and keeps its servant instead of
|
||||||
|
/// becoming a missing prefab at the next load.
|
||||||
|
///
|
||||||
|
/// TWO PREFABS EACH, forced the same way the sentry's are: a Character cannot sit in the hammer's
|
||||||
|
/// piece table, so the buildable thing is the table and the servant is instantiated by it. Unlike
|
||||||
|
/// the sentry there is no seed piece to throw away, because here the table is not scaffolding - it
|
||||||
|
/// is the anchor, the summoning point and the only interface the feature has.
|
||||||
|
///
|
||||||
|
/// WHAT WAS DELIBERATELY NOT REUSED. The design said the servant would be a RaisedThrall, and it is
|
||||||
|
/// not. RaisedThrall brings the anchor, the leash and the withering, all of which are wanted - but
|
||||||
|
/// it also brings RaisedThrallInteractPatch, which turns E on the creature into a follow command.
|
||||||
|
/// A servant that can be told to follow you out of its own circle is a servant that stops serving,
|
||||||
|
/// and "E does nothing on the servant" was decided explicitly. So the useful half is reused as a
|
||||||
|
/// static - RaisedThrall.RegisterStation / StationStandsAt, which is what makes the table findable -
|
||||||
|
/// and the anchor and wither clock are thirty lines inside BoneServantAI. The alternative was
|
||||||
|
/// editing RaisedThrall.cs, which is shared with five other chains.
|
||||||
|
/// </summary>
|
||||||
|
public static class BoneServant
|
||||||
|
{
|
||||||
|
// The smith inherits the names the single servant had, so nothing already built is orphaned.
|
||||||
|
public const string SmithName = "BoneServant";
|
||||||
|
public const string SmithTableName = "ServantTable";
|
||||||
|
public const string SmithDisplay = "Bone Smith";
|
||||||
|
public const string SmithTableDisplay = "Smith's Table";
|
||||||
|
|
||||||
|
public const string CookName = "BoneCook";
|
||||||
|
public const string CookTableName = "CookTable";
|
||||||
|
public const string CookDisplay = "Bone Cook";
|
||||||
|
public const string CookTableDisplay = "Cook's Table";
|
||||||
|
|
||||||
|
/// <summary>Vanilla's guaranteed-melee skeleton: the plain one rolls its own weapon, and the
|
||||||
|
/// point here is to have none at all.</summary>
|
||||||
|
private const string ServantSource = "Skeleton_NoArcher";
|
||||||
|
|
||||||
|
public const float Health = 100f;
|
||||||
|
|
||||||
|
/// <summary>Two circles of twenty metres cannot overlap if the tables are forty apart, which is
|
||||||
|
/// how the question of two servants of the SAME trade fighting over one chest was answered - by
|
||||||
|
/// making the situation impossible to build rather than by sharing state between them.</summary>
|
||||||
|
public const float TableSpacing = 40f;
|
||||||
|
|
||||||
|
private const float TableScale = 0.8f;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// One skull, one wishbone, eight stone - the same price for both tables.
|
||||||
|
///
|
||||||
|
/// The skull is TrophySkeleton and NOT this mod's own CursedSkull, and that is forced rather
|
||||||
|
/// than chosen: the cursed skull is bought from the Skeleton faction's merchant, so building it
|
||||||
|
/// into the cook's price would make the cook unbuildable by the only race allowed to build it.
|
||||||
|
/// A skeleton trophy is a skull anyone can go and get.
|
||||||
|
///
|
||||||
|
/// The wishbone is a real cost and worth knowing about: it is Bonemass's drop and the only
|
||||||
|
/// treasure-finder in the game, so a standing table keeps yours locked up. Recovered in full
|
||||||
|
/// when the table is removed, like every other recipe in this mod.
|
||||||
|
/// </summary>
|
||||||
|
private static RequirementConfig[] Recipe()
|
||||||
|
{
|
||||||
|
return new[]
|
||||||
|
{
|
||||||
|
new RequirementConfig("TrophySkeleton", 1, 0, true),
|
||||||
|
new RequirementConfig("Wishbone", 1, 0, true),
|
||||||
|
new RequirementConfig("Stone", 8, 0, true),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void Register()
|
||||||
|
{
|
||||||
|
if (RegisterServant(SmithName, SmithDisplay, ButlerFamily.Forge))
|
||||||
|
{
|
||||||
|
RegisterTable(SmithTableName, SmithTableDisplay, SmithName, ButlerFamily.Forge,
|
||||||
|
"A slab of bone and slate, dusted with ore. Something patient waits by the fires.",
|
||||||
|
"Coal");
|
||||||
|
|
||||||
|
PieceDensityLimit.Register(SmithTableName, TableSpacing, 1,
|
||||||
|
"Another smith's table stands within forty paces. One smith to a yard.");
|
||||||
|
|
||||||
|
// Two races, and it is the wider of the two locks: the Skeleton raises the dead to work
|
||||||
|
// for it, and Skadi's hold is a forge under ice.
|
||||||
|
PieceDensityLimit.RegisterGate(SmithTableName, (player, position) =>
|
||||||
|
{
|
||||||
|
if (SkeletonRace.IsSkeleton() || SkadiRace.IsLocalSkadi()) return true;
|
||||||
|
|
||||||
|
if (player != null)
|
||||||
|
{
|
||||||
|
player.Message(MessageHud.MessageType.Center,
|
||||||
|
"The bones do not answer to your blood.");
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (RegisterServant(CookName, CookDisplay, ButlerFamily.Kitchen))
|
||||||
|
{
|
||||||
|
RegisterTable(CookTableName, CookTableDisplay, CookName, ButlerFamily.Kitchen,
|
||||||
|
"A slab of bone and slate, worn smooth. Something patient waits by the hearth.",
|
||||||
|
"CookedMeat");
|
||||||
|
|
||||||
|
PieceDensityLimit.Register(CookTableName, TableSpacing, 1,
|
||||||
|
"Another cook's table stands within forty paces. One cook to a yard.");
|
||||||
|
|
||||||
|
// Skadi alone. A hearth kept by something dead is hers, not the Skeleton's.
|
||||||
|
PieceDensityLimit.RegisterGate(CookTableName, (player, position) =>
|
||||||
|
{
|
||||||
|
if (SkadiRace.IsLocalSkadi()) return true;
|
||||||
|
|
||||||
|
if (player != null)
|
||||||
|
{
|
||||||
|
player.Message(MessageHud.MessageType.Center,
|
||||||
|
"Only Skadi's hearth is kept by the dead.");
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------- the servants
|
||||||
|
|
||||||
|
private static bool RegisterServant(string prefabName, string displayName, ButlerFamily family)
|
||||||
|
{
|
||||||
|
GameObject prefab = PrefabManager.Instance.CreateClonedPrefab(prefabName, ServantSource);
|
||||||
|
if (prefab == null)
|
||||||
|
{
|
||||||
|
Jotunn.Logger.LogWarning($"[Butler] Could not clone {ServantSource}; " +
|
||||||
|
$"{displayName} is not registered.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Character character = prefab.GetComponent<Character>();
|
||||||
|
if (character != null)
|
||||||
|
{
|
||||||
|
character.m_name = displayName;
|
||||||
|
character.m_health = Health;
|
||||||
|
character.m_faction = Character.Faction.Players;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Nothing in its hands, and nothing to roll for. Belt and braces with the AI prefix: the
|
||||||
|
// code that would swing a weapon never runs, but a servant carrying a rusty sword around
|
||||||
|
// the kitchen would still look like a mistake.
|
||||||
|
Humanoid humanoid = prefab.GetComponent<Humanoid>();
|
||||||
|
if (humanoid != null)
|
||||||
|
{
|
||||||
|
humanoid.m_defaultItems = new GameObject[0];
|
||||||
|
humanoid.m_randomWeapon = new GameObject[0];
|
||||||
|
humanoid.m_randomArmor = new GameObject[0];
|
||||||
|
humanoid.m_randomShield = new GameObject[0];
|
||||||
|
humanoid.m_randomSets = new Humanoid.ItemSet[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
BaseAI ai = prefab.GetComponent<BaseAI>();
|
||||||
|
if (ai != null)
|
||||||
|
{
|
||||||
|
ai.m_randomMoveRange = 0f; // it never wanders: every step it takes is a decision
|
||||||
|
ai.m_avoidFire = false; // it works next to kilns for a living
|
||||||
|
ai.m_afraidOfFire = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// A servant that dropped bones would be a bone mill, exactly as with the garrison.
|
||||||
|
foreach (CharacterDrop drops in prefab.GetComponentsInChildren<CharacterDrop>(true))
|
||||||
|
{
|
||||||
|
if (drops != null) Object.DestroyImmediate(drops);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ten seconds unhurt, then two percent a second. The sentry's regeneration, whole.
|
||||||
|
prefab.AddComponent<SkeletonSentryBehaviour>();
|
||||||
|
|
||||||
|
BoneServantAI servant = prefab.AddComponent<BoneServantAI>();
|
||||||
|
servant.m_family = family;
|
||||||
|
|
||||||
|
PrefabManager.Instance.AddPrefab(prefab);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------- the tables
|
||||||
|
|
||||||
|
private static void RegisterTable(string pieceName, string displayName, string servantPrefab,
|
||||||
|
ButlerFamily family, string description, string iconSource)
|
||||||
|
{
|
||||||
|
GameObject prefab = PrefabManager.Instance.CreateClonedPrefab(pieceName, "piece_cartographytable");
|
||||||
|
if (prefab == null)
|
||||||
|
{
|
||||||
|
Jotunn.Logger.LogWarning($"[Butler] Could not clone piece_cartographytable; " +
|
||||||
|
$"the {displayName} is not registered.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// The MapTable trap, and it is the reason this is a blanket sweep by capability rather than
|
||||||
|
// a named DestroyImmediate: MapTable is Interactable AND Hoverable, so it takes the E key
|
||||||
|
// before our own Switch ever sees it and opens the shared map instead. Same bug as the
|
||||||
|
// barrel's Container on the Fenrir trough and the Trader on the vanilla wolf; the Dvergar
|
||||||
|
// contract bank pays for this lesson already.
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
prefab.transform.localScale = Vector3.one * TableScale;
|
||||||
|
|
||||||
|
ServantTableBehaviour table = prefab.AddComponent<ServantTableBehaviour>();
|
||||||
|
table.m_switch = prefab.AddComponent<Switch>();
|
||||||
|
table.m_switch.m_name = displayName;
|
||||||
|
table.m_title = displayName;
|
||||||
|
table.m_servantPrefab = servantPrefab;
|
||||||
|
table.m_family = family;
|
||||||
|
|
||||||
|
Sprite icon = BorrowIcon(iconSource) ?? BorrowIcon("TrophySkeleton");
|
||||||
|
|
||||||
|
Piece piece = prefab.GetComponent<Piece>() ?? prefab.AddComponent<Piece>();
|
||||||
|
piece.m_craftingStation = null;
|
||||||
|
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 = icon;
|
||||||
|
|
||||||
|
Piece template = PrefabManager.Cache.GetPrefab<Piece>("piece_workbench");
|
||||||
|
if (template != null && template.m_placeEffect != null) piece.m_placeEffect = template.m_placeEffect;
|
||||||
|
|
||||||
|
PieceManager.Instance.AddPiece(new CustomPiece(prefab, fixReference: false, new PieceConfig
|
||||||
|
{
|
||||||
|
Name = displayName,
|
||||||
|
Description = description,
|
||||||
|
PieceTable = PieceTables.Hammer,
|
||||||
|
Category = PieceCategories.Crafting,
|
||||||
|
Icon = icon,
|
||||||
|
Requirements = Recipe(),
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void EnsureKnown(Player player)
|
||||||
|
{
|
||||||
|
if (player == null) return;
|
||||||
|
|
||||||
|
Traverse traverse = Traverse.Create(player);
|
||||||
|
LearnPiece(traverse, SmithTableName);
|
||||||
|
LearnPiece(traverse, CookTableName);
|
||||||
|
traverse.Method("UpdateAvailablePiecesList").GetValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void LearnPiece(Traverse player, string pieceName)
|
||||||
|
{
|
||||||
|
GameObject prefab = PrefabManager.Instance.GetPrefab(pieceName);
|
||||||
|
Piece piece = prefab != null ? prefab.GetComponent<Piece>() : null;
|
||||||
|
if (piece == null) return;
|
||||||
|
|
||||||
|
player.Method("AddKnownPiece", piece).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;
|
||||||
|
return icons != null && icons.Length > 0 ? icons[0] : null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[HarmonyPatch(typeof(Player), "OnSpawned")]
|
||||||
|
public static class BoneServantKnownPatch
|
||||||
|
{
|
||||||
|
public static void Postfix(Player __instance)
|
||||||
|
{
|
||||||
|
if (__instance != Player.m_localPlayer) return;
|
||||||
|
BoneServant.EnsureKnown(__instance);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
1286
JotunnModStub/Butler/BoneServantAI.cs
Normal file
1286
JotunnModStub/Butler/BoneServantAI.cs
Normal file
File diff suppressed because it is too large
Load diff
50
JotunnModStub/Butler/ButlerConfig.cs
Normal file
50
JotunnModStub/Butler/ButlerConfig.cs
Normal file
|
|
@ -0,0 +1,50 @@
|
||||||
|
using BepInEx.Configuration;
|
||||||
|
|
||||||
|
namespace RacesOfValheim
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The four knobs the Bone Servant exposes, and deliberately only four.
|
||||||
|
///
|
||||||
|
/// Butler_BoneServant.txt sec. 14 turned down "expose everything": tick cadence, safety margins,
|
||||||
|
/// penalty-box time and the spacing between tables are constants in the code, because they are
|
||||||
|
/// numbers that get tuned once during the test and then never again - and every config entry is
|
||||||
|
/// maintained forever.
|
||||||
|
///
|
||||||
|
/// The sigil is here for a different reason from the other three. It is a PLACEHOLDER: bone
|
||||||
|
/// fragments stand in for a craftable sigil that only gets made if the feature leaves the test,
|
||||||
|
/// and being able to move the mark onto another item without a rebuild is the whole point of the
|
||||||
|
/// entry.
|
||||||
|
/// </summary>
|
||||||
|
public static class ButlerConfig
|
||||||
|
{
|
||||||
|
public static ConfigEntry<string> SigilItem;
|
||||||
|
public static ConfigEntry<float> WorkRadius;
|
||||||
|
public static ConfigEntry<float> FuelThreshold;
|
||||||
|
public static ConfigEntry<float> ResummonSeconds;
|
||||||
|
|
||||||
|
public static void Bind(ConfigFile config)
|
||||||
|
{
|
||||||
|
const string section = "Butler - Bone Servant";
|
||||||
|
|
||||||
|
SigilItem = config.Bind(section, "Sigil Item", "BoneFragments",
|
||||||
|
new ConfigDescription("Prefab name of the item that marks a chest as the servant's. " +
|
||||||
|
"A chest holding at least one of these is worked from and " +
|
||||||
|
"delivered to; every other chest is left alone. The sigil itself " +
|
||||||
|
"is never taken and never processed."));
|
||||||
|
|
||||||
|
WorkRadius = config.Bind(section, "Work Radius", 20f,
|
||||||
|
new ConfigDescription("Metres from the Servant's Table within which chests and stations " +
|
||||||
|
"are served.", new AcceptableValueRange<float>(5f, 40f)));
|
||||||
|
|
||||||
|
FuelThreshold = config.Bind(section, "Fuel Threshold", 0.25f,
|
||||||
|
new ConfigDescription("Refuel a station when its fuel drops below this fraction of its " +
|
||||||
|
"maximum, and only while it has something to work on.",
|
||||||
|
new AcceptableValueRange<float>(0f, 1f)));
|
||||||
|
|
||||||
|
ResummonSeconds = config.Bind(section, "Resummon Cooldown", 0f,
|
||||||
|
new ConfigDescription("Seconds that must pass before a fallen servant can be raised " +
|
||||||
|
"again. Zero is free and immediate, which is what the test runs on.",
|
||||||
|
new AcceptableValueRange<float>(0f, 600f)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
496
JotunnModStub/Butler/ButlerStation.cs
Normal file
496
JotunnModStub/Butler/ButlerStation.cs
Normal file
|
|
@ -0,0 +1,496 @@
|
||||||
|
using System;
|
||||||
|
using System.Reflection;
|
||||||
|
using HarmonyLib;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace RacesOfValheim
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Which servant a station belongs to.
|
||||||
|
///
|
||||||
|
/// The split is not cosmetic, it is the answer to the one complaint the first working version drew:
|
||||||
|
/// with a kitchen at one edge of the circle and three furnaces at the other, a single servant spends
|
||||||
|
/// its life walking and the margin that keeps food off the fire gets eaten by travel. Two servants
|
||||||
|
/// with two tables in the same yard walk half as far each.
|
||||||
|
///
|
||||||
|
/// It also cuts the AI in half along a seam that was already there. FORGE cannot spoil - a smelter
|
||||||
|
/// holds its ore forever and drops its own output - so the forge servant has no clock, never runs,
|
||||||
|
/// and never pre-empts itself. All of that machinery lives on in the KITCHEN, which is the only
|
||||||
|
/// place it was ever needed.
|
||||||
|
/// </summary>
|
||||||
|
public enum ButlerFamily
|
||||||
|
{
|
||||||
|
/// <summary>Smelter: furnace, blast furnace, charcoal kiln, windmill, spinning wheel, eitr
|
||||||
|
/// refinery. Nothing here has a deadline.</summary>
|
||||||
|
Forge,
|
||||||
|
|
||||||
|
/// <summary>CookingStation and Fermenter: hearths, ovens and mead. The only family with a
|
||||||
|
/// clock.</summary>
|
||||||
|
Kitchen,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// One working station, seen through the handful of questions the servant ever asks it.
|
||||||
|
///
|
||||||
|
/// THREE FAMILIES, and they are not variations on a theme - they behave OPPOSITELY on output, which
|
||||||
|
/// is the single fact the whole feature is built around (Butler_BoneServant.txt sec. 5, all of it
|
||||||
|
/// read off assembly_valheim.dll with Cecil rather than guessed):
|
||||||
|
///
|
||||||
|
/// Smelter furnace, blast furnace, charcoal kiln, windmill, spinning wheel, eitr
|
||||||
|
/// refinery. Its output FALLS ON THE GROUND BY ITSELF - UpdateSmelter runs
|
||||||
|
/// RemoveOneOre -> QueueProcessed -> SpawnProcessed with nobody asking. Nothing
|
||||||
|
/// to pull; the servant just picks the bars up.
|
||||||
|
/// CookingStation hearth, iron cooking station, stone oven. Output STAYS IN THE SLOT and keeps
|
||||||
|
/// cooking: Done at m_cookTime, Burnt at exactly twice it (verified: the IL
|
||||||
|
/// literally loads m_cookTime, pushes 2 and multiplies). This is the family that
|
||||||
|
/// can lose you food, and the only one with a clock.
|
||||||
|
/// Fermenter mead. Output stays in until the tap is opened, and never spoils.
|
||||||
|
///
|
||||||
|
/// NOTHING HERE KNOWS WHAT A MATERIAL IS. Every family exposes IsItemAllowed(string) and
|
||||||
|
/// GetItemConversion(string), matching on the PREFAB name (m_from.gameObject.name - verified), so
|
||||||
|
/// the servant asks the station "do you take this?" instead of carrying a list of ores and crops.
|
||||||
|
/// That is what makes it serve this mod's own stations, other races' stations, and other mods'
|
||||||
|
/// stations without a line of code per station.
|
||||||
|
///
|
||||||
|
/// WHY SO MUCH REFLECTION. Every one of those question methods is PRIVATE in this build -
|
||||||
|
/// GetQueueSize, IsItemAllowed, GetSlot, GetFuel, HaveDoneItem, IsFireLit, GetStatus, the lot - and
|
||||||
|
/// both Status enums are private nested types, so they cannot even be named in source. The
|
||||||
|
/// alternative was reimplementing each station's rules by reading its public m_conversion list,
|
||||||
|
/// which would be a second copy of vanilla's logic drifting out of step at the next patch. Calling
|
||||||
|
/// the real method through a cached MethodInfo is the smaller lie. The enum values are hard-coded
|
||||||
|
/// as ints, and they are not guesses: Cecil reports NotDone=0, Done=1, Burnt=2 and Empty=0,
|
||||||
|
/// Fermenting=1, Exposed=2, Ready=3.
|
||||||
|
///
|
||||||
|
/// Every write goes through InvokeRPC with the name the station REGISTERED, which carries the
|
||||||
|
/// "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.
|
||||||
|
/// </summary>
|
||||||
|
public abstract class ButlerStation
|
||||||
|
{
|
||||||
|
public Component Behaviour;
|
||||||
|
public ZNetView Nview;
|
||||||
|
public Transform Transform;
|
||||||
|
|
||||||
|
public Vector3 Position { get { return Transform.position; } }
|
||||||
|
|
||||||
|
public ZDOID Id
|
||||||
|
{
|
||||||
|
get { return Nview != null && Nview.IsValid() ? Nview.GetZDO().m_uid : ZDOID.None; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Alive { get { return Behaviour != null && Nview != null && Nview.IsValid(); } }
|
||||||
|
|
||||||
|
/// <summary>Wraps whichever of the three this object is, or null if it is not a station.</summary>
|
||||||
|
public static ButlerStation From(GameObject go)
|
||||||
|
{
|
||||||
|
if (go == null) return null;
|
||||||
|
|
||||||
|
ZNetView nview = go.GetComponent<ZNetView>();
|
||||||
|
if (nview == null || !nview.IsValid()) return null;
|
||||||
|
|
||||||
|
Smelter smelter = go.GetComponent<Smelter>();
|
||||||
|
if (smelter != null) return Fill(new SmelterStation { m_smelter = smelter }, smelter, nview);
|
||||||
|
|
||||||
|
CookingStation cooking = go.GetComponent<CookingStation>();
|
||||||
|
if (cooking != null) return Fill(new CookingStationStation { m_cooking = cooking }, cooking, nview);
|
||||||
|
|
||||||
|
Fermenter fermenter = go.GetComponent<Fermenter>();
|
||||||
|
if (fermenter != null) return Fill(new FermenterStation { m_fermenter = fermenter }, fermenter, nview);
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static ButlerStation Fill(ButlerStation station, Component behaviour, ZNetView nview)
|
||||||
|
{
|
||||||
|
station.Behaviour = behaviour;
|
||||||
|
station.Nview = nview;
|
||||||
|
station.Transform = behaviour.transform;
|
||||||
|
return station;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Taking ownership before writing is the multiplayer rule of this feature (sec. 10), and it
|
||||||
|
/// buys a second thing that matters here: once we own the ZDO the RPC runs locally and
|
||||||
|
/// immediately, so GetQueueSize and GetFuel answer truthfully on the very next line instead of
|
||||||
|
/// a network round trip later.
|
||||||
|
/// </summary>
|
||||||
|
protected void Claim()
|
||||||
|
{
|
||||||
|
if (Nview != null && Nview.IsValid() && !Nview.IsOwner()) Nview.ClaimOwnership();
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------- what the servant asks
|
||||||
|
|
||||||
|
/// <summary>Which of the two servants this one belongs to.</summary>
|
||||||
|
public abstract ButlerFamily Family { get; }
|
||||||
|
|
||||||
|
/// <summary>Can it work at all right now - fire lit, roof up? An inoperable station is skipped
|
||||||
|
/// in silence, which is a decision and not an oversight (sec. 7.7).</summary>
|
||||||
|
public abstract bool Operable { get; }
|
||||||
|
|
||||||
|
/// <summary>How many more items it can take. Zero means full.</summary>
|
||||||
|
public abstract int FreeSlots { get; }
|
||||||
|
|
||||||
|
public abstract bool Accepts(string prefabName);
|
||||||
|
|
||||||
|
/// <summary>Puts one unit in. Called FreeSlots times at most, never more.</summary>
|
||||||
|
public abstract void Add(string prefabName);
|
||||||
|
|
||||||
|
/// <summary>True while it has something to work on - so an empty furnace is never stoked.</summary>
|
||||||
|
public abstract bool HasWork { get; }
|
||||||
|
|
||||||
|
public abstract string FuelPrefab { get; }
|
||||||
|
|
||||||
|
/// <summary>Units of fuel it wants right now, already filtered by the configured threshold.</summary>
|
||||||
|
public abstract int FuelWanted { get; }
|
||||||
|
|
||||||
|
public abstract void AddFuel();
|
||||||
|
|
||||||
|
/// <summary>Something finished and needs a hand to get out. Always false for the Smelter, which
|
||||||
|
/// throws its own output on the floor.</summary>
|
||||||
|
public abstract bool HasOutput { get; }
|
||||||
|
|
||||||
|
/// <summary>Gets the finished goods onto the ground at <paramref name="at"/>, where the one
|
||||||
|
/// pickup routine will find them.</summary>
|
||||||
|
public abstract void PullOutput(Vector3 at);
|
||||||
|
|
||||||
|
/// <summary>Seconds until something in here is ruined. float.MaxValue for the two families that
|
||||||
|
/// cannot spoil, which is what keeps the urgency comparison honest without special cases.</summary>
|
||||||
|
public virtual float SecondsToSpoil { get { return float.MaxValue; } }
|
||||||
|
|
||||||
|
// ================================================================ the private doors
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Every private member of the three station classes this feature touches, resolved once.
|
||||||
|
///
|
||||||
|
/// Anything that fails to resolve stays null and its caller falls back to the safe answer -
|
||||||
|
/// "cannot tell, do not act" - so a future patch that renames one method costs that one
|
||||||
|
/// capability and a line in the log, not a servant that stands still or, worse, one that keeps
|
||||||
|
/// pouring ore into a station it can no longer read.
|
||||||
|
/// </summary>
|
||||||
|
private static class Vanilla
|
||||||
|
{
|
||||||
|
public static readonly MethodInfo SmelterQueueSize = AccessTools.Method(typeof(Smelter), "GetQueueSize");
|
||||||
|
public static readonly MethodInfo SmelterAllowed =
|
||||||
|
AccessTools.Method(typeof(Smelter), "IsItemAllowed", new[] { typeof(string) });
|
||||||
|
public static readonly MethodInfo SmelterFuel = AccessTools.Method(typeof(Smelter), "GetFuel");
|
||||||
|
public static readonly FieldInfo SmelterHaveRoof = AccessTools.Field(typeof(Smelter), "m_haveRoof");
|
||||||
|
|
||||||
|
public static readonly MethodInfo CookGetSlot = AccessTools.Method(typeof(CookingStation), "GetSlot");
|
||||||
|
public static readonly MethodInfo CookEmpty = AccessTools.Method(typeof(CookingStation), "IsEmpty");
|
||||||
|
public static readonly MethodInfo CookHaveDone = AccessTools.Method(typeof(CookingStation), "HaveDoneItem");
|
||||||
|
public static readonly MethodInfo CookAllowed =
|
||||||
|
AccessTools.Method(typeof(CookingStation), "IsItemAllowed", new[] { typeof(string) });
|
||||||
|
public static readonly MethodInfo CookConversion =
|
||||||
|
AccessTools.Method(typeof(CookingStation), "GetItemConversion", new[] { typeof(string) });
|
||||||
|
public static readonly MethodInfo CookFuel = AccessTools.Method(typeof(CookingStation), "GetFuel");
|
||||||
|
public static readonly MethodInfo CookFireLit = AccessTools.Method(typeof(CookingStation), "IsFireLit");
|
||||||
|
|
||||||
|
public static readonly MethodInfo FermenterStatus = AccessTools.Method(typeof(Fermenter), "GetStatus");
|
||||||
|
public static readonly MethodInfo FermenterAllowed =
|
||||||
|
AccessTools.Method(typeof(Fermenter), "IsItemAllowed", new[] { typeof(string) });
|
||||||
|
|
||||||
|
// 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.
|
||||||
|
public const int CookNotDone = 0;
|
||||||
|
public const int CookDone = 1;
|
||||||
|
public const int CookBurnt = 2;
|
||||||
|
|
||||||
|
public const int FermentEmpty = 0;
|
||||||
|
public const int FermentExposed = 2;
|
||||||
|
public const int FermentReady = 3;
|
||||||
|
|
||||||
|
public static bool Call(MethodInfo method, object target, bool fallback)
|
||||||
|
{
|
||||||
|
if (method == null) return fallback;
|
||||||
|
return (bool)method.Invoke(target, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int CallInt(MethodInfo method, object target, int fallback)
|
||||||
|
{
|
||||||
|
if (method == null) return fallback;
|
||||||
|
return Convert.ToInt32(method.Invoke(target, null));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static float CallFloat(MethodInfo method, object target, float fallback)
|
||||||
|
{
|
||||||
|
if (method == null) return fallback;
|
||||||
|
return Convert.ToSingle(method.Invoke(target, null));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool Allowed(MethodInfo method, object target, string prefabName)
|
||||||
|
{
|
||||||
|
if (method == null || string.IsNullOrEmpty(prefabName)) return false;
|
||||||
|
return (bool)method.Invoke(target, new object[] { prefabName });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ================================================================ Smelter
|
||||||
|
|
||||||
|
private class SmelterStation : ButlerStation
|
||||||
|
{
|
||||||
|
public Smelter m_smelter;
|
||||||
|
|
||||||
|
public override ButlerFamily Family { get { return ButlerFamily.Forge; } }
|
||||||
|
|
||||||
|
public override bool Operable
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (!m_smelter.m_requiresRoof) return true;
|
||||||
|
if (Vanilla.SmelterHaveRoof == null) return true; // cannot tell: let it try
|
||||||
|
return (bool)Vanilla.SmelterHaveRoof.GetValue(m_smelter);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private int Queued { get { return Vanilla.CallInt(Vanilla.SmelterQueueSize, m_smelter, int.MaxValue); } }
|
||||||
|
|
||||||
|
public override int FreeSlots
|
||||||
|
{
|
||||||
|
get { return Mathf.Max(0, m_smelter.m_maxOre - Queued); }
|
||||||
|
}
|
||||||
|
|
||||||
|
public override bool Accepts(string prefabName)
|
||||||
|
{
|
||||||
|
return Vanilla.Allowed(Vanilla.SmelterAllowed, m_smelter, prefabName);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Add(string prefabName)
|
||||||
|
{
|
||||||
|
Claim();
|
||||||
|
Nview.InvokeRPC("RPC_AddOre", prefabName);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override bool HasWork { get { return Queued > 0; } }
|
||||||
|
|
||||||
|
public override string FuelPrefab
|
||||||
|
{
|
||||||
|
get { return m_smelter.m_fuelItem != null ? m_smelter.m_fuelItem.gameObject.name : null; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public override int FuelWanted
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (m_smelter.m_fuelItem == null || m_smelter.m_maxFuel <= 0) return 0;
|
||||||
|
if (!HasWork) return 0;
|
||||||
|
|
||||||
|
float fuel = Vanilla.CallFloat(Vanilla.SmelterFuel, m_smelter, float.MaxValue);
|
||||||
|
if (fuel >= m_smelter.m_maxFuel * ButlerConfig.FuelThreshold.Value) return 0;
|
||||||
|
|
||||||
|
return Mathf.Max(0, Mathf.FloorToInt(m_smelter.m_maxFuel - fuel));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void AddFuel()
|
||||||
|
{
|
||||||
|
Claim();
|
||||||
|
Nview.InvokeRPC("RPC_AddFuel");
|
||||||
|
}
|
||||||
|
|
||||||
|
// The whole point of this family: nothing to collect, it drops its own.
|
||||||
|
public override bool HasOutput { get { return false; } }
|
||||||
|
public override void PullOutput(Vector3 at) { }
|
||||||
|
}
|
||||||
|
|
||||||
|
// ================================================================ CookingStation
|
||||||
|
|
||||||
|
private class CookingStationStation : ButlerStation
|
||||||
|
{
|
||||||
|
public CookingStation m_cooking;
|
||||||
|
|
||||||
|
public override ButlerFamily Family { get { return ButlerFamily.Kitchen; } }
|
||||||
|
|
||||||
|
private int SlotCount
|
||||||
|
{
|
||||||
|
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>
|
||||||
|
private bool ReadSlot(int index, out string name, out float cooked, out int status)
|
||||||
|
{
|
||||||
|
name = null;
|
||||||
|
cooked = 0f;
|
||||||
|
status = Vanilla.CookNotDone;
|
||||||
|
|
||||||
|
if (Vanilla.CookGetSlot == null) return false;
|
||||||
|
|
||||||
|
object[] args = new object[] { index, null, null, null };
|
||||||
|
Vanilla.CookGetSlot.Invoke(m_cooking, args);
|
||||||
|
|
||||||
|
name = args[1] as string;
|
||||||
|
cooked = Convert.ToSingle(args[2]);
|
||||||
|
status = Convert.ToInt32(args[3]);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override bool Operable
|
||||||
|
{
|
||||||
|
get { return !m_cooking.m_requireFire || Vanilla.Call(Vanilla.CookFireLit, m_cooking, false); }
|
||||||
|
}
|
||||||
|
|
||||||
|
public override int FreeSlots
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
int free = 0;
|
||||||
|
for (int i = 0; i < SlotCount; i++)
|
||||||
|
{
|
||||||
|
string name;
|
||||||
|
float cooked;
|
||||||
|
int status;
|
||||||
|
if (!ReadSlot(i, out name, out cooked, out status)) return 0;
|
||||||
|
if (string.IsNullOrEmpty(name)) free++;
|
||||||
|
}
|
||||||
|
return free;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public override bool Accepts(string prefabName)
|
||||||
|
{
|
||||||
|
return Vanilla.Allowed(Vanilla.CookAllowed, m_cooking, prefabName);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Add(string prefabName)
|
||||||
|
{
|
||||||
|
Claim();
|
||||||
|
Nview.InvokeRPC("RPC_AddItem", prefabName);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override bool HasWork { get { return !Vanilla.Call(Vanilla.CookEmpty, m_cooking, true); } }
|
||||||
|
|
||||||
|
public override string FuelPrefab
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return m_cooking.m_useFuel && m_cooking.m_fuelItem != null
|
||||||
|
? m_cooking.m_fuelItem.gameObject.name
|
||||||
|
: null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public override int FuelWanted
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (!m_cooking.m_useFuel || m_cooking.m_fuelItem == null || m_cooking.m_maxFuel <= 0) return 0;
|
||||||
|
if (!HasWork) return 0;
|
||||||
|
|
||||||
|
float fuel = Vanilla.CallFloat(Vanilla.CookFuel, m_cooking, float.MaxValue);
|
||||||
|
if (fuel >= m_cooking.m_maxFuel * ButlerConfig.FuelThreshold.Value) return 0;
|
||||||
|
|
||||||
|
return Mathf.Max(0, Mathf.FloorToInt(m_cooking.m_maxFuel - fuel));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void AddFuel()
|
||||||
|
{
|
||||||
|
Claim();
|
||||||
|
Nview.InvokeRPC("RPC_AddFuel");
|
||||||
|
}
|
||||||
|
|
||||||
|
public override bool HasOutput { get { return Vanilla.Call(Vanilla.CookHaveDone, m_cooking, false); } }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// ONE per done slot, and the 1 is not a stylistic choice. RPC_RemoveDoneItem spawns the
|
||||||
|
/// item <c>amount</c> times PER SLOT (verified in the IL: the inner loop runs to the
|
||||||
|
/// argument), so passing anything above 1 would not collect faster - it would print money.
|
||||||
|
/// </summary>
|
||||||
|
public override void PullOutput(Vector3 at)
|
||||||
|
{
|
||||||
|
Claim();
|
||||||
|
Nview.InvokeRPC("RPC_RemoveDoneItem", at, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The clock this whole feature exists for. Done at m_cookTime, Burnt at 2x - so what is
|
||||||
|
/// left is 2*cookTime - cookedTime, and a slot already Done is the urgent one because its
|
||||||
|
/// remaining half is all that stands between dinner and charcoal.
|
||||||
|
///
|
||||||
|
/// GetItemConversion is asked with whatever name the slot currently holds, which is the raw
|
||||||
|
/// item before Done and the COOKED one after: CookingStation.GetItemConversion matches on
|
||||||
|
/// both m_from and m_to (verified), so the cook time is readable in either phase.
|
||||||
|
/// </summary>
|
||||||
|
public override float SecondsToSpoil
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (Vanilla.CookConversion == null) return float.MaxValue;
|
||||||
|
|
||||||
|
float soonest = float.MaxValue;
|
||||||
|
|
||||||
|
for (int i = 0; i < SlotCount; i++)
|
||||||
|
{
|
||||||
|
string name;
|
||||||
|
float cooked;
|
||||||
|
int status;
|
||||||
|
if (!ReadSlot(i, out name, out cooked, out status)) break;
|
||||||
|
|
||||||
|
if (string.IsNullOrEmpty(name)) continue;
|
||||||
|
if (status == Vanilla.CookBurnt) continue; // already lost, no hurry
|
||||||
|
|
||||||
|
CookingStation.ItemConversion conversion =
|
||||||
|
Vanilla.CookConversion.Invoke(m_cooking, new object[] { name })
|
||||||
|
as CookingStation.ItemConversion;
|
||||||
|
if (conversion == null) continue;
|
||||||
|
|
||||||
|
float left = conversion.m_cookTime * 2f - cooked;
|
||||||
|
if (left < soonest) soonest = left;
|
||||||
|
}
|
||||||
|
|
||||||
|
return soonest;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ================================================================ Fermenter
|
||||||
|
|
||||||
|
private class FermenterStation : ButlerStation
|
||||||
|
{
|
||||||
|
public Fermenter m_fermenter;
|
||||||
|
|
||||||
|
/// <summary>Mead goes with the food. It has no deadline of its own, so it costs the cook
|
||||||
|
/// nothing beyond one more thing to fill and one more tap to open.</summary>
|
||||||
|
public override ButlerFamily Family { get { return ButlerFamily.Kitchen; } }
|
||||||
|
|
||||||
|
private int Status
|
||||||
|
{
|
||||||
|
get { return Vanilla.CallInt(Vanilla.FermenterStatus, m_fermenter, Vanilla.FermentExposed); }
|
||||||
|
}
|
||||||
|
|
||||||
|
public override bool Operable { get { return Status != Vanilla.FermentExposed; } }
|
||||||
|
|
||||||
|
public override int FreeSlots { get { return Status == Vanilla.FermentEmpty ? 1 : 0; } }
|
||||||
|
|
||||||
|
public override bool Accepts(string prefabName)
|
||||||
|
{
|
||||||
|
return Vanilla.Allowed(Vanilla.FermenterAllowed, m_fermenter, prefabName);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Add(string prefabName)
|
||||||
|
{
|
||||||
|
Claim();
|
||||||
|
Nview.InvokeRPC("RPC_AddItem", prefabName);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override bool HasWork { get { return Status != Vanilla.FermentEmpty; } }
|
||||||
|
|
||||||
|
public override string FuelPrefab { get { return null; } }
|
||||||
|
public override int FuelWanted { get { return 0; } }
|
||||||
|
public override void AddFuel() { }
|
||||||
|
|
||||||
|
public override bool HasOutput { get { return Status == Vanilla.FermentReady; } }
|
||||||
|
|
||||||
|
/// <summary>Opens the tap. The bottles are not out yet when this returns - DelayedTap waits
|
||||||
|
/// m_tapDelay for the animation - so the servant collects them on a later pass, which the
|
||||||
|
/// pickup sweep handles without knowing anything about fermenting.</summary>
|
||||||
|
public override void PullOutput(Vector3 at)
|
||||||
|
{
|
||||||
|
Claim();
|
||||||
|
Nview.InvokeRPC("RPC_Tap");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
170
JotunnModStub/Butler/ServantTableBehaviour.cs
Normal file
170
JotunnModStub/Butler/ServantTableBehaviour.cs
Normal file
|
|
@ -0,0 +1,170 @@
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace RacesOfValheim
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// A servant's table: an anchor, a summoning point and the feature's only window. One class serves
|
||||||
|
/// both trades - what changes between the smith's and the cook's is three fields set at
|
||||||
|
/// registration, not behaviour.
|
||||||
|
///
|
||||||
|
/// It does no work of its own. Everything it knows it asks the servant, and everything the servant
|
||||||
|
/// says it says here - the hover text is the ONE feedback channel this feature has, by decision, so
|
||||||
|
/// a servant that has stopped must be able to explain itself from a line of text or it is
|
||||||
|
/// indistinguishable from a broken mod.
|
||||||
|
///
|
||||||
|
/// E RAISES, and that is all E does. There is no pause switch and no automatic re-forming: a fallen
|
||||||
|
/// servant leaves the table empty until somebody notices. That was chosen over a sixty-second
|
||||||
|
/// respawn on the grounds that a death nobody notices is a death that might as well not happen.
|
||||||
|
///
|
||||||
|
/// It registers itself with RaisedThrall's station list, which is what BoneServantAI's wither clock
|
||||||
|
/// asks when it wants to know whether its table is still standing. That list is the only part of
|
||||||
|
/// the thrall machinery this feature uses.
|
||||||
|
/// </summary>
|
||||||
|
public class ServantTableBehaviour : MonoBehaviour
|
||||||
|
{
|
||||||
|
public Switch m_switch;
|
||||||
|
|
||||||
|
/// <summary>Set on the prefab at registration, so both travel to every instance.</summary>
|
||||||
|
public string m_title = "Servant's Table";
|
||||||
|
public string m_servantPrefab = BoneServant.SmithName;
|
||||||
|
public ButlerFamily m_family = ButlerFamily.Forge;
|
||||||
|
|
||||||
|
private const string KeyLastRaise = "RoV_butlerRaisedAt";
|
||||||
|
|
||||||
|
/// <summary>Where the servant stands up: in front of the table, clear of the mesh.</summary>
|
||||||
|
private const float RaiseOffset = 1.2f;
|
||||||
|
|
||||||
|
private ZNetView m_nview;
|
||||||
|
|
||||||
|
private void Awake()
|
||||||
|
{
|
||||||
|
RaisedThrall.RegisterStation(transform);
|
||||||
|
|
||||||
|
m_nview = GetComponent<ZNetView>();
|
||||||
|
|
||||||
|
if (m_switch != null)
|
||||||
|
{
|
||||||
|
m_switch.m_onUse = OnUse;
|
||||||
|
m_switch.m_onHover = Hover;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnDestroy()
|
||||||
|
{
|
||||||
|
RaisedThrall.UnregisterStation(transform);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------- interaction
|
||||||
|
|
||||||
|
private bool OnUse(Switch caller, Humanoid user, ItemDrop.ItemData item)
|
||||||
|
{
|
||||||
|
Player player = user as Player;
|
||||||
|
if (player == null) return false;
|
||||||
|
|
||||||
|
if (item != null)
|
||||||
|
{
|
||||||
|
player.Message(MessageHud.MessageType.Center, "$msg_wontwork");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Servant() != null)
|
||||||
|
{
|
||||||
|
player.Message(MessageHud.MessageType.Center, "It is already at work.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
float wait = Cooldown();
|
||||||
|
if (wait > 0f)
|
||||||
|
{
|
||||||
|
player.Message(MessageHud.MessageType.Center,
|
||||||
|
$"The bones are not ready. {Mathf.CeilToInt(wait)}s.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return Raise(player);
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool Raise(Player player)
|
||||||
|
{
|
||||||
|
if (m_nview == null || !m_nview.IsValid()) return false;
|
||||||
|
if (ZNetScene.instance == null) return false;
|
||||||
|
|
||||||
|
GameObject prefab = ZNetScene.instance.GetPrefab(m_servantPrefab);
|
||||||
|
if (prefab == null)
|
||||||
|
{
|
||||||
|
Jotunn.Logger.LogWarning($"[Butler] No '{m_servantPrefab}' in ZNetScene; nothing was raised.");
|
||||||
|
player.Message(MessageHud.MessageType.Center, "Nothing answers.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Owner-only, so in multiplayer exactly one servant stands up rather than one per client.
|
||||||
|
m_nview.ClaimOwnership();
|
||||||
|
|
||||||
|
Vector3 at = transform.position + transform.forward * RaiseOffset;
|
||||||
|
GameObject spawned = Object.Instantiate(prefab, at, Quaternion.identity);
|
||||||
|
|
||||||
|
BoneServantAI servant = spawned.GetComponent<BoneServantAI>();
|
||||||
|
if (servant != null) servant.Bind(transform.position);
|
||||||
|
|
||||||
|
if (ZNet.instance != null) m_nview.GetZDO().Set(KeyLastRaise, ZNet.instance.GetTime().Ticks);
|
||||||
|
|
||||||
|
player.Message(MessageHud.MessageType.Center, "The servant rises.");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>Seconds still to wait, or zero. Kept in world time so logging out does not pay it off
|
||||||
|
/// for free - and configured to zero for the test, where it is simply never in the way.</summary>
|
||||||
|
private float Cooldown()
|
||||||
|
{
|
||||||
|
if (m_nview == null || !m_nview.IsValid() || ZNet.instance == null) return 0f;
|
||||||
|
|
||||||
|
float required = ButlerConfig.ResummonSeconds.Value;
|
||||||
|
if (required <= 0f) return 0f;
|
||||||
|
|
||||||
|
long stamp = m_nview.GetZDO().GetLong(KeyLastRaise, 0L);
|
||||||
|
if (stamp == 0L) return 0f;
|
||||||
|
|
||||||
|
double elapsed = (ZNet.instance.GetTime() - new System.DateTime(stamp)).TotalSeconds;
|
||||||
|
return Mathf.Max(0f, required - (float)elapsed);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------- the hover
|
||||||
|
|
||||||
|
private string Hover()
|
||||||
|
{
|
||||||
|
BoneServantAI servant = Servant();
|
||||||
|
|
||||||
|
if (servant == null)
|
||||||
|
{
|
||||||
|
return m_title + "\nNo servant stands here.\n" +
|
||||||
|
"[<color=yellow><b>$KEY_Use</b></color>] Raise one";
|
||||||
|
}
|
||||||
|
|
||||||
|
string status = servant.Status;
|
||||||
|
if (string.IsNullOrEmpty(status)) status = "Waiting.";
|
||||||
|
|
||||||
|
return m_title + "\n" + status;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// This table's servant, if it is alive and loaded.
|
||||||
|
///
|
||||||
|
/// Matched by anchor rather than by a stored id, so a table rebuilt on the same spot adopts the
|
||||||
|
/// servant already standing there - and by TRADE as well, because a smith's table and a cook's
|
||||||
|
/// table are allowed to stand a metre apart and must not adopt each other's servant.
|
||||||
|
/// </summary>
|
||||||
|
private BoneServantAI Servant()
|
||||||
|
{
|
||||||
|
foreach (Character character in Character.GetAllCharacters())
|
||||||
|
{
|
||||||
|
if (character == null || character.IsDead()) continue;
|
||||||
|
|
||||||
|
BoneServantAI servant = character.GetComponent<BoneServantAI>();
|
||||||
|
if (servant == null || servant.m_family != m_family) continue;
|
||||||
|
if (servant.IsBoundTo(transform.position)) return servant;
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -295,6 +295,17 @@ namespace RacesOfValheim
|
||||||
// Trol/TrolTotemStore.cs, which is generic and is deliberately NOT copied here.
|
// Trol/TrolTotemStore.cs, which is generic and is deliberately NOT copied here.
|
||||||
Trader trader = prefab.GetComponent<Trader>() ?? prefab.AddComponent<Trader>();
|
Trader trader = prefab.GetComponent<Trader>() ?? prefab.AddComponent<Trader>();
|
||||||
trader.m_name = PieceDisplayName;
|
trader.m_name = PieceDisplayName;
|
||||||
|
|
||||||
|
// DISABLED ON PURPOSE, and it is the line that keeps the log clean. Trader was written for
|
||||||
|
// Haldor, who is a creature with an animator and a LookAt rig: Trader.Update() calls
|
||||||
|
// m_animator.SetBool("Stand", ...) and m_lookAt.ResetTarget() with no null check on every
|
||||||
|
// frame no player is nearby, and Trader.Start() calls InvokeRepeating("RandomTalk", 0, 0)
|
||||||
|
// on a component nobody authored in the editor. On a table both of those are null, so the
|
||||||
|
// bank threw a NullReferenceException every frame from the moment it was built. A disabled
|
||||||
|
// component runs neither, and StoreGui needs neither: Show() only reads fields off the
|
||||||
|
// Trader and asks it for its item list, and GetComponent finds it disabled just the same.
|
||||||
|
// This is the same fix SvermHiveStore.Mount already carries for the Hive Market.
|
||||||
|
trader.enabled = false;
|
||||||
trader.m_items = new List<Trader.TradeItem>();
|
trader.m_items = new List<Trader.TradeItem>();
|
||||||
trader.m_useItems = new List<Trader.TraderUseItem>();
|
trader.m_useItems = new List<Trader.TraderUseItem>();
|
||||||
trader.m_randomTalk = new List<string>();
|
trader.m_randomTalk = new List<string>();
|
||||||
|
|
|
||||||
|
|
@ -11,19 +11,63 @@ namespace RacesOfValheim
|
||||||
// notices the player - not what a "press E to talk" merchant should do. Skipping Update()
|
// notices the player - not what a "press E to talk" merchant should do. Skipping Update()
|
||||||
// entirely leaves Interactable.Interact() (E opens StoreGui) and Hoverable.GetHoverText()
|
// entirely leaves Interactable.Interact() (E opens StoreGui) and Hoverable.GetHoverText()
|
||||||
// (the "E - Talk" prompt) untouched, since neither of those depends on Update() running.
|
// (the "E - Talk" prompt) untouched, since neither of those depends on Update() running.
|
||||||
|
//
|
||||||
|
// The same prefix also refuses to run Update() on a Trader that has no rig to drive, which is
|
||||||
|
// the general form of a bug that reached a tester: Trader.Start() resolves m_animator and
|
||||||
|
// m_lookAt with GetComponentInChildren, and Update() then dereferences BOTH with no null check -
|
||||||
|
// m_animator.SetBool("Stand", ...) and m_lookAt.ResetTarget() on the branch taken whenever no
|
||||||
|
// player is nearby, which is most frames. A building is not a creature and has neither, so a
|
||||||
|
// Trader bolted onto one threw a NullReferenceException every frame and filled the BepInEx
|
||||||
|
// console. The prefabs that do that (the Dvergar bank, the Trol totem, the Hive Market) now
|
||||||
|
// disable their Trader outright, which is the real fix; this check is the net under it, and it
|
||||||
|
// costs one cached field read per trader per frame.
|
||||||
[HarmonyPatch(typeof(Trader), "Update")]
|
[HarmonyPatch(typeof(Trader), "Update")]
|
||||||
public static class FactionMerchantSuppressAmbientPatch
|
public static class FactionMerchantSuppressAmbientPatch
|
||||||
{
|
{
|
||||||
|
// Both fields are private in the assembly this project compiles against. Resolved once
|
||||||
|
// rather than through Traverse, because this runs on every trader on every frame.
|
||||||
|
private static readonly AccessTools.FieldRef<Trader, Animator> AnimatorField =
|
||||||
|
AccessTools.FieldRefAccess<Trader, Animator>("m_animator");
|
||||||
|
private static readonly AccessTools.FieldRef<Trader, LookAt> LookAtField =
|
||||||
|
AccessTools.FieldRefAccess<Trader, LookAt>("m_lookAt");
|
||||||
|
|
||||||
public static bool Prefix(Trader __instance)
|
public static bool Prefix(Trader __instance)
|
||||||
{
|
{
|
||||||
if (((Component)__instance).GetComponent<FactionMerchant>() != null)
|
if (((Component)__instance).GetComponent<FactionMerchant>() != null)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (AnimatorField(__instance) == null || LookAtField(__instance) == null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Trader.Start() ends with InvokeRepeating("RandomTalk", m_randomTalkInterval,
|
||||||
|
// m_randomTalkInterval), and a Trader added with AddComponent comes up with that interval at
|
||||||
|
// zero, because nobody authored it in the editor. On a faction merchant the repeat is pure
|
||||||
|
// waste for as long as the creature exists: RandomTalk's first act is to read the animator's
|
||||||
|
// "Stand" bool, and nothing ever sets it, because Update() - the only thing that would - is
|
||||||
|
// suppressed for these by the patch above. So it wakes up, asks one question, answers no, and
|
||||||
|
// is scheduled again.
|
||||||
|
//
|
||||||
|
// Cancelled in a postfix rather than by skipping Start with a prefix: Start also resolves
|
||||||
|
// m_animator and m_lookAt and snaps a SnapToGround rig to the terrain, and none of that is in
|
||||||
|
// the way. Only the timer is.
|
||||||
|
[HarmonyPatch(typeof(Trader), "Start")]
|
||||||
|
public static class FactionMerchantStopRandomTalkPatch
|
||||||
|
{
|
||||||
|
public static void Postfix(Trader __instance)
|
||||||
|
{
|
||||||
|
if (((Component)__instance).GetComponent<FactionMerchant>() == null) return;
|
||||||
|
__instance.CancelInvoke("RandomTalk");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Player.FindHoverObject() always figures out m_hoveringCreature correctly (it only
|
// Player.FindHoverObject() always figures out m_hoveringCreature correctly (it only
|
||||||
// needs a Character component on the hit collider, no Hoverable/Interactable
|
// needs a Character component on the hit collider, no Hoverable/Interactable
|
||||||
// involved) but separately sets m_hovering - the field the "E - Talk" prompt and the
|
// involved) but separately sets m_hovering - the field the "E - Talk" prompt and the
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ namespace RacesOfValheim
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Claws that are part of the body, for the races that grow a pair.
|
/// Claws that are part of the body, for the races that grow a pair.
|
||||||
///
|
///
|
||||||
/// This is SvermClawSlot generalised, not reinvented: the Sverm's Vilebone Maulclaws worked out
|
/// This is SvermClawSlot generalised, not reinvented: the Sverm's Chitin Claws worked out
|
||||||
/// the whole shape of the problem, and the Aswid and the Fenrir are asking for the same object
|
/// the whole shape of the problem, and the Aswid and the Fenrir are asking for the same object
|
||||||
/// with a different face. So the machinery moved here and each race supplies only what is
|
/// with a different face. So the machinery moved here and each race supplies only what is
|
||||||
/// genuinely its own - the item name, the model to wear, and whether it is currently a wolf.
|
/// genuinely its own - the item name, the model to wear, and whether it is currently a wolf.
|
||||||
|
|
@ -178,6 +178,15 @@ namespace RacesOfValheim
|
||||||
shared.m_weight = 0f;
|
shared.m_weight = 0f;
|
||||||
shared.m_maxQuality = 1;
|
shared.m_maxQuality = 1;
|
||||||
|
|
||||||
|
// INDESTRUCTIBLE, and it has to be the flag rather than a big number. The claws are
|
||||||
|
// never crafted, so no workbench will ever repair them: left on normal durability
|
||||||
|
// they wear down to zero and Humanoid.EquipItem then refuses to put them back in
|
||||||
|
// hand, which strands the race bare-fisted for good. m_useDurability = false is the
|
||||||
|
// single switch every path reads - the attack drain, the broken-item check, the
|
||||||
|
// inventory bar and the tooltip line all skip the item entirely.
|
||||||
|
shared.m_useDurability = false;
|
||||||
|
shared.m_canBeReparied = false;
|
||||||
|
|
||||||
// No recipe and no station: this item is never crafted, only issued.
|
// No recipe and no station: this item is never crafted, only issued.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -375,6 +384,11 @@ namespace RacesOfValheim
|
||||||
Jotunn.Logger.LogInfo($"[{RaceId}] Issued the {DisplayName}.");
|
Jotunn.Logger.LogInfo($"[{RaceId}] Issued the {DisplayName}.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// A pair issued before the claws stopped wearing out is still carrying whatever it had
|
||||||
|
// ground down to. Nothing reads that number any more, but it is saved with the item, so
|
||||||
|
// it is put back to full once rather than left as a stale figure in the save file.
|
||||||
|
if (claws.m_durability < claws.GetMaxDurability()) claws.m_durability = claws.GetMaxDurability();
|
||||||
|
|
||||||
// Empty-handed means clawed. Anything else in the right hand wins until it is put away,
|
// Empty-handed means clawed. Anything else in the right hand wins until it is put away,
|
||||||
// which is the whole compromise.
|
// which is the whole compromise.
|
||||||
ItemDrop.ItemData held = Traverse.Create((Humanoid)player).Field<ItemDrop.ItemData>("m_rightItem").Value;
|
ItemDrop.ItemData held = Traverse.Create((Humanoid)player).Field<ItemDrop.ItemData>("m_rightItem").Value;
|
||||||
|
|
|
||||||
|
|
@ -135,7 +135,7 @@ namespace RacesOfValheim
|
||||||
|
|
||||||
sb.AppendLine("[Base Passive] Insect Metabolism: You eat everything anyone else eats, and honey is worth double to you. Alchemical blood is the one thing you will not swallow.\n");
|
sb.AppendLine("[Base Passive] Insect Metabolism: You eat everything anyone else eats, and honey is worth double to you. Alchemical blood is the one thing you will not swallow.\n");
|
||||||
|
|
||||||
sb.AppendLine($"[Base Passive] Vilebone Maulclaws: Your hands are the weapon. Bare-handed blows land at {rules.ClawDamagePercent * 100f:0}% of the claws' full weight, and they cannot be taken from you - draw a sword and they wait, sheathe it and they are back.\n");
|
sb.AppendLine($"[Base Passive] Chitin Claws: Your hands are the weapon. Bare-handed blows land at {rules.ClawDamagePercent * 100f:0}% of the claws' full weight, and they cannot be taken from you - draw a sword and they wait, sheathe it and they are back.\n");
|
||||||
|
|
||||||
if (rules.MetabolicSurge)
|
if (rules.MetabolicSurge)
|
||||||
sb.AppendLine("[Eikthyr Unlock] Metabolic Surge: Running and jumping cost you less, and you jump higher.\n");
|
sb.AppendLine("[Eikthyr Unlock] Metabolic Surge: Running and jumping cost you less, and you jump higher.\n");
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ namespace RacesOfValheim
|
||||||
{
|
{
|
||||||
public const string PluginGUID = "com.nandor.racesofvalheim";
|
public const string PluginGUID = "com.nandor.racesofvalheim";
|
||||||
public const string PluginName = "Races Of Valheim";
|
public const string PluginName = "Races Of Valheim";
|
||||||
public const string PluginVersion = "1.4.2";
|
public const string PluginVersion = "1.4.3";
|
||||||
|
|
||||||
private readonly Harmony harmony = new Harmony(PluginGUID);
|
private readonly Harmony harmony = new Harmony(PluginGUID);
|
||||||
|
|
||||||
|
|
@ -43,6 +43,9 @@ namespace RacesOfValheim
|
||||||
// Not a race either: a tool any race can craft, so it sits beside the vulture rather
|
// Not a race either: a tool any race can craft, so it sits beside the vulture rather
|
||||||
// than inside the alphabetical run above.
|
// than inside the alphabetical run above.
|
||||||
TrolsHammerConfig.Bind(Config);
|
TrolsHammerConfig.Bind(Config);
|
||||||
|
// Not a race either: the two Bone Servants, shared by the Skeleton and Skadi, so they
|
||||||
|
// bind here rather than inside either race's run.
|
||||||
|
ButlerConfig.Bind(Config);
|
||||||
harmony.PatchAll();
|
harmony.PatchAll();
|
||||||
gameObject.AddComponent<FenrirRace>();
|
gameObject.AddComponent<FenrirRace>();
|
||||||
gameObject.AddComponent<SkadiRace>();
|
gameObject.AddComponent<SkadiRace>();
|
||||||
|
|
@ -130,6 +133,7 @@ namespace RacesOfValheim
|
||||||
SvermRace.Instance.CreateModAssets();
|
SvermRace.Instance.CreateModAssets();
|
||||||
WarVultureItem.Register();
|
WarVultureItem.Register();
|
||||||
TrolsHammerItem.Register();
|
TrolsHammerItem.Register();
|
||||||
|
BoneServant.Register();
|
||||||
}
|
}
|
||||||
// --- RACE SELECTION UI ---
|
// --- RACE SELECTION UI ---
|
||||||
public void ShowRaceSelectionMenu()
|
public void ShowRaceSelectionMenu()
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ using UnityEngine;
|
||||||
namespace RacesOfValheim
|
namespace RacesOfValheim
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The Maulclaws as a REAL equipped weapon, sitting in the inventory in plain sight and
|
/// The Chitin Claws as a REAL equipped weapon, sitting in the inventory in plain sight and
|
||||||
/// refusing to be moved.
|
/// refusing to be moved.
|
||||||
///
|
///
|
||||||
/// WHY THIS REPLACED THE COSMETIC VERSION. Bolting a model to the hand bones worked, but the
|
/// WHY THIS REPLACED THE COSMETIC VERSION. Bolting a model to the hand bones worked, but the
|
||||||
|
|
@ -36,8 +36,13 @@ namespace RacesOfValheim
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static class SvermClawSlot
|
public static class SvermClawSlot
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The prefab id, and it keeps the old spelling on purpose: it is what every save on disk
|
||||||
|
/// names the item by, and renaming it would leave a Sverm holding an item ObjectDB can no
|
||||||
|
/// longer resolve. The display name below is the only half a player ever reads.
|
||||||
|
/// </summary>
|
||||||
public const string ItemName = "SvermMaulclaws";
|
public const string ItemName = "SvermMaulclaws";
|
||||||
public const string ItemDisplayName = "Vilebone Maulclaws";
|
public const string ItemDisplayName = "Chitin Claws";
|
||||||
|
|
||||||
/// <summary>Row in the reserved column the claws sit on. The other three await the carapace.</summary>
|
/// <summary>Row in the reserved column the claws sit on. The other three await the carapace.</summary>
|
||||||
private const int ClawRow = 0;
|
private const int ClawRow = 0;
|
||||||
|
|
@ -84,6 +89,15 @@ namespace RacesOfValheim
|
||||||
shared.m_weight = 0f;
|
shared.m_weight = 0f;
|
||||||
shared.m_maxQuality = 1;
|
shared.m_maxQuality = 1;
|
||||||
|
|
||||||
|
// INDESTRUCTIBLE, and it has to be the flag rather than a big number. The claws are
|
||||||
|
// never crafted, so no workbench will ever repair them: left on normal durability
|
||||||
|
// they wear down to zero and Humanoid.EquipItem then refuses to put them back in
|
||||||
|
// hand, which strands the Sverm bare-fisted for good. m_useDurability = false is the
|
||||||
|
// single switch every path reads - the attack drain, the broken-item check, the
|
||||||
|
// inventory bar and the tooltip line all skip the item entirely.
|
||||||
|
shared.m_useDurability = false;
|
||||||
|
shared.m_canBeReparied = false;
|
||||||
|
|
||||||
// No recipe and no station: this item is never crafted, only issued.
|
// No recipe and no station: this item is never crafted, only issued.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -153,9 +167,14 @@ namespace RacesOfValheim
|
||||||
claws.m_gridPos = corner;
|
claws.m_gridPos = corner;
|
||||||
}
|
}
|
||||||
|
|
||||||
Jotunn.Logger.LogInfo("[Sverm] Issued the Maulclaws.");
|
Jotunn.Logger.LogInfo("[Sverm] Issued the Chitin Claws.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// A pair issued before the claws stopped wearing out is still carrying whatever it had
|
||||||
|
// ground down to. Nothing reads that number any more, but it is saved with the item, so
|
||||||
|
// it is put back to full once rather than left as a stale figure in the save file.
|
||||||
|
if (claws.m_durability < claws.GetMaxDurability()) claws.m_durability = claws.GetMaxDurability();
|
||||||
|
|
||||||
// Empty-handed means clawed. Anything else in the right hand wins until it is put
|
// Empty-handed means clawed. Anything else in the right hand wins until it is put
|
||||||
// away, which is the whole compromise.
|
// away, which is the whole compromise.
|
||||||
ItemDrop.ItemData held = Traverse.Create((Humanoid)player).Field<ItemDrop.ItemData>("m_rightItem").Value;
|
ItemDrop.ItemData held = Traverse.Create((Humanoid)player).Field<ItemDrop.ItemData>("m_rightItem").Value;
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ using UnityEngine;
|
||||||
namespace RacesOfValheim
|
namespace RacesOfValheim
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The Vilebone Maulclaws: attached to the hands for good, and never equipped.
|
/// The Chitin Claws: attached to the hands for good, and never equipped.
|
||||||
///
|
///
|
||||||
/// WHY NOT A REAL WEAPON. Valheim has one weapon slot. A claw that is genuinely equipped locks
|
/// WHY NOT A REAL WEAPON. Valheim has one weapon slot. A claw that is genuinely equipped locks
|
||||||
/// the Sverm out of every sword, bow and staff in the game for the whole run, which is not
|
/// the Sverm out of every sword, bow and staff in the game for the whole run, which is not
|
||||||
|
|
@ -52,7 +52,7 @@ namespace RacesOfValheim
|
||||||
if (candidate != null)
|
if (candidate != null)
|
||||||
{
|
{
|
||||||
resolved = candidate;
|
resolved = candidate;
|
||||||
Jotunn.Logger.LogInfo($"[Sverm] Maulclaws resolved to '{name}'.");
|
Jotunn.Logger.LogInfo($"[Sverm] Chitin Claws resolved to '{name}'.");
|
||||||
return resolved;
|
return resolved;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -70,7 +70,7 @@ namespace RacesOfValheim
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The vanilla weapon's damage at quality 4, read once. This is the ceiling the tier
|
/// The vanilla weapon's damage at quality 4, read once. This is the ceiling the tier
|
||||||
/// percentages are a fraction of, and state 7 is 100% of it - the real Maulclaws.
|
/// percentages are a fraction of, and state 7 is 100% of it - the real Chitin Claws.
|
||||||
///
|
///
|
||||||
/// Public because it is the shared yardstick: the Aswid's and the Fenrir's claws
|
/// Public because it is the shared yardstick: the Aswid's and the Fenrir's claws
|
||||||
/// (RaceClawSet) are balanced against this same figure rather than against the models they
|
/// (RaceClawSet) are balanced against this same figure rather than against the models they
|
||||||
|
|
@ -108,7 +108,7 @@ namespace RacesOfValheim
|
||||||
};
|
};
|
||||||
|
|
||||||
referenceRead = true;
|
referenceRead = true;
|
||||||
Jotunn.Logger.LogInfo($"[Sverm] Maulclaws at quality {SvermConfig.ArmorReferenceQuality}: " +
|
Jotunn.Logger.LogInfo($"[Sverm] Chitin Claws at quality {SvermConfig.ArmorReferenceQuality}: " +
|
||||||
$"slash {referenceDamage.m_slash:0.#}, pierce {referenceDamage.m_pierce:0.#}, " +
|
$"slash {referenceDamage.m_slash:0.#}, pierce {referenceDamage.m_pierce:0.#}, " +
|
||||||
$"blunt {referenceDamage.m_blunt:0.#}.");
|
$"blunt {referenceDamage.m_blunt:0.#}.");
|
||||||
return referenceDamage;
|
return referenceDamage;
|
||||||
|
|
|
||||||
|
|
@ -88,7 +88,7 @@ namespace RacesOfValheim
|
||||||
public const string CarapaceLegsVisual = "ArmorCarapaceLegs";
|
public const string CarapaceLegsVisual = "ArmorCarapaceLegs";
|
||||||
public const string CarapaceHelmetVisual = "HelmetCarapace";
|
public const string CarapaceHelmetVisual = "HelmetCarapace";
|
||||||
|
|
||||||
// ─── Vilebone Maulclaws ──────────────────────────────────────────────
|
// ─── Chitin Claws ────────────────────────────────────────────────────
|
||||||
// FOUR near-identical names exist in the manifest and only some carry a recipe, so the
|
// FOUR near-identical names exist in the manifest and only some carry a recipe, so the
|
||||||
// prefab is resolved by trying them in order and logging which one answered. A wrong guess
|
// prefab is resolved by trying them in order and logging which one answered. A wrong guess
|
||||||
// here fails soft and silently - two empty hands - which is exactly the failure this
|
// here fails soft and silently - two empty hands - which is exactly the failure this
|
||||||
|
|
@ -106,7 +106,7 @@ namespace RacesOfValheim
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Fraction of the vanilla weapon's quality-4 damage the bare hands hit for, per state.
|
/// Fraction of the vanilla weapon's quality-4 damage the bare hands hit for, per state.
|
||||||
/// State 7 is the ceiling - the real Maulclaws - and state 8 adds fire on top rather than
|
/// State 7 is the ceiling - the real Chitin Claws - and state 8 adds fire on top rather than
|
||||||
/// going past it. Index 0 unused, as above.
|
/// going past it. Index 0 unused, as above.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static readonly float[] ClawDamagePercentByState =
|
public static readonly float[] ClawDamagePercentByState =
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,7 @@ namespace RacesOfValheim
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public float FireWeakness;
|
public float FireWeakness;
|
||||||
|
|
||||||
/// <summary>Fraction of the Maulclaws' quality-4 damage a bare-handed blow lands for.</summary>
|
/// <summary>Fraction of the Chitin Claws' quality-4 damage a bare-handed blow lands for.</summary>
|
||||||
public float ClawDamagePercent;
|
public float ClawDamagePercent;
|
||||||
|
|
||||||
public bool MetabolicSurge; // cheaper running and jumping, higher jump
|
public bool MetabolicSurge; // cheaper running and jumping, higher jump
|
||||||
|
|
|
||||||
|
|
@ -84,7 +84,7 @@ namespace RacesOfValheim
|
||||||
//
|
//
|
||||||
// The first version emptied the hands completely and the form could not attack: with
|
// The first version emptied the hands completely and the form could not attack: with
|
||||||
// nothing equipped there is no weapon to swing, and Valheim's bare fist is not the
|
// nothing equipped there is no weapon to swing, and Valheim's bare fist is not the
|
||||||
// thing this form is supposed to be throwing. Leaving the Maulclaws equipped makes the
|
// thing this form is supposed to be throwing. Leaving the Chitin Claws equipped makes the
|
||||||
// sting an ordinary weapon attack - which works - and costs nothing visually, because
|
// sting an ordinary weapon attack - which works - and costs nothing visually, because
|
||||||
// the whole body is hidden a line later. Fist weapons report Skills.SkillType.Unarmed,
|
// the whole body is hidden a line later. Fist weapons report Skills.SkillType.Unarmed,
|
||||||
// so the damage patch still recognises the blow and swaps the deathsquito's figure in.
|
// so the damage patch still recognises the blow and swaps the deathsquito's figure in.
|
||||||
|
|
@ -254,7 +254,7 @@ namespace RacesOfValheim
|
||||||
}
|
}
|
||||||
|
|
||||||
Jotunn.Logger.LogWarning($"[Sverm] Could not read a weapon off '{SvermConfig.StingerCreature}'; " +
|
Jotunn.Logger.LogWarning($"[Sverm] Could not read a weapon off '{SvermConfig.StingerCreature}'; " +
|
||||||
"the sting falls back to the Maulclaws.");
|
"the sting falls back to the Chitin Claws.");
|
||||||
stingerDamageRead = true;
|
stingerDamageRead = true;
|
||||||
return stingerDamage; // all zeroes: the damage patch then leaves the claw values alone
|
return stingerDamage; // all zeroes: the damage patch then leaves the claw values alone
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ namespace RacesOfValheim
|
||||||
/// matures on screen as it advances.
|
/// matures on screen as it advances.
|
||||||
///
|
///
|
||||||
/// What gets mounted, all of it borrowed from vanilla:
|
/// What gets mounted, all of it borrowed from vanilla:
|
||||||
/// the claws - the Vilebone Maulclaws, on both hands, always;
|
/// the claws - the Chitin Claws, on both hands, always;
|
||||||
/// the spines - UndeadBjornRibcage worn spine-up, a static crest, from tier 5;
|
/// the spines - UndeadBjornRibcage worn spine-up, a static crest, from tier 5;
|
||||||
/// the eyes - two emissive spheres, the Aswid's geometry unchanged;
|
/// the eyes - two emissive spheres, the Aswid's geometry unchanged;
|
||||||
/// the motes - a firefly swarm under the body, only while falling;
|
/// the motes - a firefly swarm under the body, only while falling;
|
||||||
|
|
|
||||||
|
|
@ -261,6 +261,17 @@ namespace RacesOfValheim
|
||||||
// GameObject - walks straight into Say(m_randomStartTrade, ...) right after opening the store.
|
// GameObject - walks straight into Say(m_randomStartTrade, ...) right after opening the store.
|
||||||
Trader trader = prefab.GetComponent<Trader>() ?? prefab.AddComponent<Trader>();
|
Trader trader = prefab.GetComponent<Trader>() ?? prefab.AddComponent<Trader>();
|
||||||
trader.m_name = PieceDisplayName;
|
trader.m_name = PieceDisplayName;
|
||||||
|
|
||||||
|
// DISABLED ON PURPOSE, and it is the line that keeps the log clean. Trader was written for
|
||||||
|
// Haldor, who is a creature with an animator and a LookAt rig: Trader.Update() calls
|
||||||
|
// m_animator.SetBool("Stand", ...) and m_lookAt.ResetTarget() with no null check on every
|
||||||
|
// frame no player is nearby, and Trader.Start() calls InvokeRepeating("RandomTalk", 0, 0)
|
||||||
|
// on a component nobody authored in the editor. On a totem both of those are null, so the
|
||||||
|
// piece threw a NullReferenceException every frame from the moment it was raised. A
|
||||||
|
// disabled component runs neither, and StoreGui needs neither: Show() only reads fields off
|
||||||
|
// the Trader and asks it for its item list, and GetComponent finds it disabled just the
|
||||||
|
// same. This is the same fix SvermHiveStore.Mount already carries for the Hive Market.
|
||||||
|
trader.enabled = false;
|
||||||
trader.m_items = new List<Trader.TradeItem>();
|
trader.m_items = new List<Trader.TradeItem>();
|
||||||
trader.m_useItems = new List<Trader.TraderUseItem>();
|
trader.m_useItems = new List<Trader.TraderUseItem>();
|
||||||
trader.m_randomTalk = new List<string>();
|
trader.m_randomTalk = new List<string>();
|
||||||
|
|
|
||||||
25
README.md
25
README.md
|
|
@ -4,7 +4,13 @@ A comprehensive Valheim mod allowing you to play as unique races, each providing
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## New Patch v1.4.2: The Sverm
|
## New Patch v1.4.3
|
||||||
|
|
||||||
|
The War Vulture is craftable at last, Trol's Hammer builds everything 20% bigger, and two portal bugs are gone. See the [Changelog](#changelog).
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## The Sverm
|
||||||
|
|
||||||
The tenth race is an insect. The Sverm never dresses: chest, legs and helm are carapace that never comes off and is always worth a full set of the biome ahead of you — best quality, weightless, no movement penalty. It fights with claws it cannot put down, poison cannot touch it, and no invertebrate in the game will attack it from tier zero. Blunt and fire hit it 40% harder, which is the price.
|
The tenth race is an insect. The Sverm never dresses: chest, legs and helm are carapace that never comes off and is always worth a full set of the biome ahead of you — best quality, weightless, no movement penalty. It fights with claws it cannot put down, poison cannot touch it, and no invertebrate in the game will attack it from tier zero. Blunt and fire hit it 40% harder, which is the price.
|
||||||
|
|
||||||
|
|
@ -87,7 +93,7 @@ Full details under [Sverm](#10-sverm) and [Sverm Progression](#race-progressions
|
||||||
|
|
||||||
### 10. Sverm
|
### 10. Sverm
|
||||||
- **Chitin Plating:** You never dress. Chest, legs and helm are carapace worth a full set of the biome ahead of you at every tier — best quality, weightless, no movement penalty. Only cloak and trinket may still be worn.
|
- **Chitin Plating:** You never dress. Chest, legs and helm are carapace worth a full set of the biome ahead of you at every tier — best quality, weightless, no movement penalty. Only cloak and trinket may still be worn.
|
||||||
- **Vilebone Maulclaws:** Your hands are the weapon — see [Permanent Claws](#permanent-claws).
|
- **Chitin Claws:** Your hands are the weapon — see [Permanent Claws](#permanent-claws).
|
||||||
- **Hive Pheromones:** No invertebrate attacks you — leeches, ticks, deathsquitos, seekers and bees all ignore you, from tier zero.
|
- **Hive Pheromones:** No invertebrate attacks you — leeches, ticks, deathsquitos, seekers and bees all ignore you, from tier zero.
|
||||||
- **Toxin Immunity:** Poison cannot touch you. Blunt and fire hit you 40% harder — until Fader, when the fire weakness burns out and comes back as a resistance.
|
- **Toxin Immunity:** Poison cannot touch you. Blunt and fire hit you 40% harder — until Fader, when the fire weakness burns out and comes back as a resistance.
|
||||||
- **The Colony:** After the Elder, a Brood Mound, a Hive Market and a roster of insect troops bought with digested biomass.
|
- **The Colony:** After the Elder, a Brood Mound, a Hive Market and a roster of insect troops bought with digested biomass.
|
||||||
|
|
@ -101,7 +107,7 @@ Three races grow a pair of their own. The terms are identical for all three: iss
|
||||||
|
|
||||||
- **Aswid — Claws of the Beast:** burned almost black. Lands the whole of it as slash.
|
- **Aswid — Claws of the Beast:** burned almost black. Lands the whole of it as slash.
|
||||||
- **Fenrir — Cursed Claws:** the flesh rippers worn as the game made them. Also pure slash.
|
- **Fenrir — Cursed Claws:** the flesh rippers worn as the game made them. Also pure slash.
|
||||||
- **Sverm — Vilebone Maulclaws:** splits the same weight three ways, and sets it alight at Fader.
|
- **Sverm — Chitin Claws:** splits the same weight three ways, and sets it alight at Fader.
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|
@ -218,7 +224,7 @@ Right Mouse toggles flight. Glide towards aim, W = forward/climb, Shift+W = use
|
||||||
<details>
|
<details>
|
||||||
<summary><strong>Sverm Progression</strong></summary>
|
<summary><strong>Sverm Progression</strong></summary>
|
||||||
|
|
||||||
- **Base:** Chitin Plating (full next-biome set at every tier, weightless, no speed penalty; only cloak and trinket wearable). Toxin Immunity — poison cannot touch you, but +40% blunt and +40% fire damage taken. Hive Pheromones — no invertebrate attacks you. Insect Metabolism — eats everything, honey counts double, alchemical blood is the one refusal. Vilebone Maulclaws — unarmed blows land at a share of the claws' full weight, rising with every tier.
|
- **Base:** Chitin Plating (full next-biome set at every tier, weightless, no speed penalty; only cloak and trinket wearable). Toxin Immunity — poison cannot touch you, but +40% blunt and +40% fire damage taken. Hive Pheromones — no invertebrate attacks you. Insect Metabolism — eats everything, honey counts double, alchemical blood is the one refusal. Chitin Claws — unarmed blows land at a share of the claws' full weight, rising with every tier.
|
||||||
- **Eikthyr:** Metabolic Surge – running and jumping cost less, and you jump higher. Ventral Pouches – +100 carry weight.
|
- **Eikthyr:** Metabolic Surge – running and jumping cost less, and you jump higher. Ventral Pouches – +100 carry weight.
|
||||||
- **Elder:** Grinding Mandibles – seeds are food (raw nourishment, no garden buffs). Sensory Antennae – feel what lives around you, through stone and soil. **The colony wakes:** Brood Mound unlocked.
|
- **Elder:** Grinding Mandibles – seeds are food (raw nourishment, no garden buffs). Sensory Antennae – feel what lives around you, through stone and soil. **The colony wakes:** Brood Mound unlocked.
|
||||||
- **Bonemass:** Venom Glands – every blow carries bonus poison, growing per tier. Acid Hemolymph – melee attackers take poison back.
|
- **Bonemass:** Venom Glands – every blow carries bonus poison, growing per tier. Acid Hemolymph – melee attackers take poison back.
|
||||||
|
|
@ -385,17 +391,22 @@ The **Sverm** belongs to no faction. Its Hive Pheromones make every invertebrate
|
||||||
## Development & Feedback
|
## Development & Feedback
|
||||||
|
|
||||||
This is a stable release, but more races and refinements are planned!
|
This is a stable release, but more races and refinements are planned!
|
||||||
Bug reports, feedback, ideas: [https://discord.gg/gbBEK2VTE](https://discord.gg/gbBEK2VTE)
|
Bug reports, feedback, ideas: [https://discord.gg/gbBEK2VTE](https://discord.gg/gbBEK2VTE)
|
||||||
|
Support the mod: [Patreon — NandorTheModder](https://www.patreon.com/c/NandorTheModder)
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## Changelog
|
## Changelog
|
||||||
|
|
||||||
|
### v1.4.3
|
||||||
|
- **NEW - Trol's Hammer:** a second builder's hammer (1 Core Wood, 2 Fine Wood, Workbench) that builds everything the ordinary one builds, 20% larger. Any race can craft it.
|
||||||
|
- **War Vulture:** now craftable — 10 Greydwarf Eyes, 2 Black Metal, 2 Raw Lox Meat at a Forge. The recipe only appears for the races that can ride.
|
||||||
|
- **Fix - Portals:** teleporting no longer leaves you in a world that has stopped loading, and the Skeleton's head flame no longer burns torches into the world for everyone to find.
|
||||||
|
|
||||||
### v1.4.2
|
### v1.4.2
|
||||||
- **NEW - Sverm Race:** the tenth race. Wears carapace instead of armour (never removable, always worth the next biome's full set, weightless), fights with permanent claws, is immune to poison but takes 40% more from blunt and fire, and is ignored by every invertebrate in the game from tier zero. After the Elder it stops being one body and becomes a colony.
|
- **NEW - Sverm Race:** the tenth race. Wears carapace instead of armour (never removable, always worth the next biome's full set, weightless), fights with permanent claws, is immune to poison but takes 40% more from blunt and fire, and is ignored by every invertebrate in the game from tier zero. After the Elder it stops being one body and becomes a colony.
|
||||||
- **NEW - The Colony (Sverm):** Brood Mound, digestion bank, brood eggs on a timer, an insect troop roster, a Hive Market, blister ticks that regrow free, and vanilla beehives taken over by the nest — twice the speed, three times the honey, royal jelly after Yagluth.
|
- **NEW - The Colony (Sverm):** Brood Mound, digestion bank, brood eggs on a timer, an insect troop roster, a Hive Market, blister ticks that regrow free, and vanilla beehives taken over by the nest — twice the speed, three times the honey, royal jelly after Yagluth.
|
||||||
- **NEW - War Vulture (Flying Mount):** a vulture trophy on a stick that puts you on a real, network-visible flying bird. Unlimited cruise, a limited sprint reserve on the run key that refills in mid-air, and its own bar under your stamina. Furling and Dvergar by default, configurable. Crafted at a forge from 10 greydwarf eyes, 2 black metal ingots and 2 raw lox meat, and the recipe is hidden from every race that cannot ride.
|
- **NEW - War Vulture (Flying Mount):** a vulture trophy on a stick that puts you on a real, network-visible flying bird. Unlimited cruise, a limited sprint reserve on the run key that refills in mid-air, and its own bar under your stamina. Furling and Dvergar by default, configurable. No recipe yet while the flight is being proven — spawn it from the console.
|
||||||
- **NEW - Trol's Hammer:** a second builder's hammer (1 Core Wood, 2 Fine Wood, Workbench) that builds everything the ordinary one builds — same menu, same cost, same drop — 20% larger. The preview is already at full size, the size is saved with the piece and shared with other players, and both hammers keep working side by side in the same house.
|
|
||||||
- **NEW - Claws for the Aswid and the Fenrir:** both races now grow a permanent pair, on the same terms the Sverm has always had. All three are measured against **one** yardstick rather than against the models they wear, so the same tier is worth the same damage whichever race you are, and no pair counts while you are wearing another body.
|
- **NEW - Claws for the Aswid and the Fenrir:** both races now grow a permanent pair, on the same terms the Sverm has always had. All three are measured against **one** yardstick rather than against the models they wear, so the same tier is worth the same damage whichever race you are, and no pair counts while you are wearing another body.
|
||||||
- **NEW - Dvergar Contract Bank:** the hire bench is now a proper contract bank — five crew slots, 400 to 2000 coin, paid at your own trader discount, with the Queen's drop opening the Runic Crew and the Ash Guard. Hired crews keep their employer's truce with the mountain's dvergr, seekers at heel included, so a band walking into an outpost no longer means a dead shopkeeper. They carry no loot, heal themselves, and a dead crew is money spent. Race locked, one per square kilometre, and the only chain that needs no reagent — the Dvergar pay for everything, so 100 coin goes in the recipe instead.
|
- **NEW - Dvergar Contract Bank:** the hire bench is now a proper contract bank — five crew slots, 400 to 2000 coin, paid at your own trader discount, with the Queen's drop opening the Runic Crew and the Ash Guard. Hired crews keep their employer's truce with the mountain's dvergr, seekers at heel included, so a band walking into an outpost no longer means a dead shopkeeper. They carry no loot, heal themselves, and a dead crew is money spent. Race locked, one per square kilometre, and the only chain that needs no reagent — the Dvergar pay for everything, so 100 coin goes in the recipe instead.
|
||||||
- **NEW - Dvergar Rune Barrel:** 20 doses of any vanilla brew, poured into everything you have raised within 30 m. It refuses nothing and promises nothing: a healing mead heals a dvergr, a stamina mead does nothing, because a creature has no stamina bar.
|
- **NEW - Dvergar Rune Barrel:** 20 doses of any vanilla brew, poured into everything you have raised within 30 m. It refuses nothing and promises nothing: a healing mead heals a dvergr, a stamina mead does nothing, because a creature has no stamina bar.
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
{
|
{
|
||||||
"name": "RacesOfValheim",
|
"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.",
|
"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.2",
|
"version_number": "1.4.3",
|
||||||
"website_url": "",
|
"website_url": "",
|
||||||
"dependencies": [
|
"dependencies": [
|
||||||
"denikson-BepInExPack_Valheim-5.4.2333",
|
"denikson-BepInExPack_Valheim-5.4.2333",
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue