RacesOfValheim/JotunnModStub/Alfar/AlfarChests.cs
kanym 06cc1d8c88 feat: the Ljoskjarne becomes a floating steel pyramid
A 2 m pyramid of dark steel, carved with Valheim's runes, hovers 0.5 m
above the ground, bobs and turns slowly. A cyan rib runs down each face;
it breathes and burns brighter while crystals wait. One still collider
keeps building, support and the E key as before. New hammer icon.
2026-10-30 18:48:32 +01:00

148 lines
6.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",
"$rov_hover_alfar_inngangskista", new Color(0.62f, 0.80f, 1f, 1f),
AlfarInputChest.Build, "AlfarInputChest_icon.png");
RegisterOne(WoodName, "$rov_piece_alfar_eldividarkista_name", "$rov_piece_alfar_eldividarkista_desc",
"$rov_hover_alfar_eldividarkista", new Color(0.85f, 0.62f, 0.36f, 1f),
AlfarFireChest.Build, "AlfarFireChest_icon.png");
}
private static void RegisterOne(string pieceName, string display, string description, string hoverName, Color tint,
System.Func<GameObject, bool> build, string iconResource)
{
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));
// The hover and the chest window say what the chest is for, not only its name.
Container container = prefab.GetComponent<Container>();
if (container != null) container.m_name = hoverName;
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;
// Each chest has a body of its own; the tint stays as the fallback if it cannot be built.
Sprite icon = piece.m_icon;
if (!build(prefab)) AlfarConstructs.Tint(prefab, tint);
else icon = IconFrom(iconResource) ?? icon;
PieceManager.Instance.AddPiece(new CustomPiece(prefab, fixReference: false, new PieceConfig
{
Name = display,
Description = description,
PieceTable = PieceTables.Hammer,
Category = PieceCategories.Crafting,
Icon = 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);
}
internal static Sprite IconFrom(string resource)
{
Texture2D texture = PieceLook.LoadTexture(resource);
if (texture == null) return null;
return Sprite.Create(texture, new Rect(0f, 0f, texture.width, texture.height), new Vector2(0.5f, 0.5f));
}
}
}