RacesOfValheim/JotunnModStub/Alfar/AlfarChests.cs
Ferdinando 3f8cf1ee27 feat(alfar): v1.6.0 - the Alfar, an eleventh race
Grey, tall and thin, with black eyes. Eitr is armour and fuel (shield,
diet, soft fall, levitation), Heimkall sends a lethal blow home at one
health every 20 minutes. Caster powers from Skrid to the archon
Sameining, with on-screen cooldowns. Automated base around the
Ljoskjarne: drones, three constructs, crystals, Ljosgard, Prismavard.
Compendium page in EN/IT/RU.

README: New in block, race section, progression, station line, changelog.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-25 17:38:28 +01:00

134 lines
5.8 KiB
C#

using System.Collections.Generic;
using Jotunn.Configs;
using Jotunn.Entities;
using Jotunn.Managers;
using UnityEngine;
namespace RacesOfValheim
{
/// <summary>
/// The EIRINNSIGLI, the verdigris seal (Alfar_Progettazione.txt sec. 9.2c): a bronze nail turned at
/// the forge. Put inside a chest it tells the drones NOT to look there - the inverse of the
/// Butler's, where the seal says "this one is yours". Only the colour differs from the nail: a model
/// recolour does not touch the inventory icon (guide 5.2), so in the pack it looks like a bronze
/// nail and only the name tells it apart.
/// </summary>
public static class AlfarSigil
{
public const string PrefabName = "AlfarSigil";
public const string DisplayName = "$rov_item_alfar_sigil_name";
public static void Register()
{
GameObject prefab = PrefabManager.Instance.CreateClonedPrefab(PrefabName, "BronzeNails");
if (prefab == null)
{
Jotunn.Logger.LogWarning("[Alfar] Could not clone BronzeNails: no verdigris seal.");
return;
}
ItemDrop drop = prefab.GetComponent<ItemDrop>();
if (drop == null || drop.m_itemData == null || drop.m_itemData.m_shared == null) return;
ItemDrop.ItemData.SharedData shared = drop.m_itemData.m_shared;
shared.m_name = DisplayName;
shared.m_description = "$rov_item_alfar_sigil_desc";
AlfarConstructs.Tint(prefab, new Color(0.36f, 0.68f, 0.58f, 1f));
ItemManager.Instance.AddItem(new CustomItem(prefab, fixReference: false));
ItemManager.Instance.AddRecipe(new CustomRecipe(new RecipeConfig
{
Item = PrefabName,
Amount = 1,
CraftingStation = CraftingStations.Forge,
MinStationLevel = 1,
Requirements = new[] { new RequirementConfig("BronzeNails", 1, 0, true) },
}));
}
}
/// <summary>
/// The two special chests (sec. 9.2c): built like an ordinary chest with Greydwarf eyes added to
/// the price. The ENTRY chest is where everything is thrown and where the drones sort from; the
/// WOOD chest holds the wood the drones may burn - the only wood they ever consume.
/// </summary>
public static class AlfarChests
{
public const string EntryName = "AlfarInngangskista";
public const string WoodName = "AlfarEldividarkista";
public static void Register()
{
RegisterOne(EntryName, "$rov_piece_alfar_inngangskista_name", "$rov_piece_alfar_inngangskista_desc",
new Color(0.62f, 0.80f, 1f, 1f));
RegisterOne(WoodName, "$rov_piece_alfar_eldividarkista_name", "$rov_piece_alfar_eldividarkista_desc",
new Color(0.85f, 0.62f, 0.36f, 1f));
}
private static void RegisterOne(string pieceName, string display, string description, Color tint)
{
GameObject source = PrefabManager.Cache.GetPrefab<GameObject>("piece_chest_wood");
if (source == null)
{
Jotunn.Logger.LogWarning("[Alfar] No 'piece_chest_wood': the chest " + pieceName + " is not registered.");
return;
}
GameObject prefab = PrefabManager.Instance.CreateClonedPrefab(pieceName, source);
if (prefab == null) return;
// The price of a plain chest, read from the game (guide 3.2), plus the eyes.
var requirements = new List<RequirementConfig>();
Piece vanilla = source.GetComponent<Piece>();
if (vanilla != null && vanilla.m_resources != null)
{
foreach (Piece.Requirement r in vanilla.m_resources)
{
if (r.m_resItem == null) continue;
requirements.Add(new RequirementConfig(r.m_resItem.gameObject.name, r.m_amount, 0, true));
}
}
requirements.Add(new RequirementConfig("GreydwarfEye", AlfarNexusConfig.ChestEyes.Value, 0, true));
Container container = prefab.GetComponent<Container>();
if (container != null) container.m_name = display;
Piece piece = prefab.GetComponent<Piece>();
if (piece == null) { Jotunn.Logger.LogWarning("[Alfar] The chest has no Piece: " + pieceName); return; }
piece.m_name = display;
piece.m_description = description;
AlfarConstructs.Tint(prefab, tint);
PieceManager.Instance.AddPiece(new CustomPiece(prefab, fixReference: false, new PieceConfig
{
Name = display,
Description = description,
PieceTable = PieceTables.Hammer,
Category = PieceCategories.Crafting,
Icon = piece.m_icon,
Requirements = requirements.ToArray(),
}));
// One of each inside the reach of a Ljoskjarne, and only for the Alfar, and only where a core stands.
PieceDensityLimit.Register(pieceName, AlfarNexusConfig.NexusRadius.Value, 1, "rov_msg_build_limit_alfar_chest");
PieceDensityLimit.RegisterGate(pieceName, (player, position) =>
{
if (!AlfarRace.IsLocalAlfar())
{
if (player != null) player.Message(MessageHud.MessageType.Center, ModText.Get("rov_msg_alfar_only_alfar"));
return false;
}
if (AlfarNexusBehaviour.Covering(position) == null)
{
if (player != null) player.Message(MessageHud.MessageType.Center, ModText.Get("rov_msg_alfar_chest_needs_nexus"));
return false;
}
return true;
});
AlfarPieces.Extra.Add(pieceName);
}
}
}