Players mistook a plain Wood chest for the Eldividarkista, so neither Alfar chest looks like a buildable vanilla chest any more. Eldividarkista: the Mistlands dvergr crate stretched to 1.6 x 0.8 m, blackened iron with a bronze frame and an iron grate on the front. The grate glows and throws sparks only while the chest holds wood the drones may burn. Inngangskista: the dvergr town loot chest, navy steel with silver trim. A cyan line in the lid shines while it holds anything but the sigil. Both have new hammer icons, and their hover names say their role (input, fuel) in English, Italian and Russian. If a borrowed vanilla model is missing, the chest falls back to the old tinted wood chest. scripts/paint_*_chest.py repaint the textures and render previews and icons offline with scripts/render_obj.py.
166 lines
8.7 KiB
C#
166 lines
8.7 KiB
C#
using System.Collections.Generic;
|
|
using Jotunn.Managers;
|
|
using UnityEngine;
|
|
|
|
namespace RacesOfValheim
|
|
{
|
|
/// <summary>
|
|
/// The Eldividarkista's own body. Players kept mistaking a plain "Wood chest" for it, so it must
|
|
/// not look like any chest they can build: the box and lid are the Mistlands dvergr crate (a prop
|
|
/// nobody can place), repainted as blackened iron with an aged-bronze frame
|
|
/// (scripts/paint_fire_chest.py), with an iron grate on the front.
|
|
///
|
|
/// Behind the grate the fire shows only while the chest holds wood the drones may burn: a dark
|
|
/// grate means empty. No light source, on purpose - a base full of chests must not glow.
|
|
/// </summary>
|
|
public static class AlfarFireChest
|
|
{
|
|
private const string CrateName = "dvergrprops_crate";
|
|
private const string EmbersSource = "fx_Torch_Carried";
|
|
|
|
// The crate is a 1.02 m cube, stretched into a chest about the size of the vanilla one:
|
|
// 1.6 m wide, 0.8 m deep. Its front face (+z, away from the lid's hinge) ends up here.
|
|
private static readonly Vector3 Stretch = new Vector3(1.6f, 1f, 0.8f);
|
|
private const float FrontZ = 0.515f * 0.8f;
|
|
private const float LidY = 0.81f;
|
|
private const float GrateWidth = 0.62f * 1.6f;
|
|
private const int GrateGaps = 10;
|
|
private const float GrateHeight = 0.36f;
|
|
private const float GrateY = 0.42f;
|
|
|
|
private static readonly Color Ember = new Color(1f, 0.42f, 0.1f);
|
|
|
|
/// <summary>Swaps the cloned wood chest's meshes for the fire chest. False leaves the wood
|
|
/// chest's look in place, with a warning, rather than an invisible chest.</summary>
|
|
public static bool Build(GameObject prefab)
|
|
{
|
|
GameObject crate = PrefabManager.Cache.GetPrefab<GameObject>(CrateName);
|
|
Transform crateNew = crate != null ? crate.transform.Find("new") : null;
|
|
Transform visual = prefab.transform.Find("New");
|
|
if (crateNew == null || crateNew.childCount < 3 || visual == null)
|
|
{
|
|
Jotunn.Logger.LogWarning("[Alfar] No dvergr crate to build the Eldividarkista from; it keeps the wood chest's look.");
|
|
return false;
|
|
}
|
|
|
|
// The wood chest's box, lids and LOD group go; "New" itself stays, because WearNTear
|
|
// switches it as the piece's healthy look.
|
|
for (int i = visual.childCount - 1; i >= 0; i--) Object.DestroyImmediate(visual.GetChild(i).gameObject);
|
|
LODGroup lod = visual.GetComponent<LODGroup>();
|
|
if (lod != null) Object.DestroyImmediate(lod);
|
|
|
|
// The crate's high meshes, in the order the prefab keeps them: box, contents, lid. The
|
|
// contents are the glowing dvergr cargo and stay behind.
|
|
GameObject body = Object.Instantiate(crateNew.GetChild(0).gameObject, visual, false);
|
|
body.name = "body";
|
|
body.transform.localScale = Vector3.Scale(body.transform.localScale, Stretch);
|
|
GameObject lidClosed = Object.Instantiate(crateNew.GetChild(2).gameObject, visual, false);
|
|
lidClosed.name = "lid_closed";
|
|
lidClosed.transform.localScale = Vector3.Scale(lidClosed.transform.localScale, Stretch);
|
|
|
|
// The open lid: the closed one turned up 100 degrees about its back edge.
|
|
GameObject lidOpen = Object.Instantiate(lidClosed, visual, false);
|
|
lidOpen.name = "lid_open";
|
|
foreach (Collider collider in lidOpen.GetComponentsInChildren<Collider>(true)) Object.DestroyImmediate(collider);
|
|
Vector3 hinge = new Vector3(0f, LidY, -FrontZ);
|
|
Quaternion turn = Quaternion.Euler(-100f, 0f, 0f);
|
|
lidOpen.transform.localPosition = hinge + turn * (lidClosed.transform.localPosition - hinge);
|
|
lidOpen.transform.localRotation = turn * lidClosed.transform.localRotation;
|
|
lidOpen.SetActive(false);
|
|
|
|
Container container = prefab.GetComponent<Container>();
|
|
if (container != null)
|
|
{
|
|
container.m_open = lidOpen;
|
|
container.m_closed = lidClosed;
|
|
}
|
|
|
|
// Only a retextured material is a copy; without the paint, writing to it would change every
|
|
// dvergr crate in the Mistlands too.
|
|
Texture2D paint = PieceLook.LoadTexture("AlfarFireChest_d.png");
|
|
if (paint != null) PieceLook.Retexture(visual, new Dictionary<string, Texture> { { "Crate_d", paint } });
|
|
Material iron = paint != null ? body.GetComponent<MeshRenderer>()?.sharedMaterial : null;
|
|
if (iron != null)
|
|
{
|
|
// The crate's normal map is wood planks; on plates it would draw seams that are not there.
|
|
if (iron.HasProperty("_BumpMap")) iron.SetTexture("_BumpMap", null);
|
|
if (iron.HasProperty("_Metallic")) iron.SetFloat("_Metallic", 0.6f);
|
|
if (iron.HasProperty("_Glossiness")) iron.SetFloat("_Glossiness", 0.45f);
|
|
}
|
|
|
|
Transform grate = BuildGrate(visual, iron, out Renderer glow);
|
|
ParticleSystem embers = AddEmbers(grate);
|
|
|
|
AlfarChestGlow look = prefab.AddComponent<AlfarChestGlow>();
|
|
look.Glows = new[] { glow };
|
|
look.Embers = embers;
|
|
look.GlowColor = Ember * 2f;
|
|
look.WoodOnly = true;
|
|
return true;
|
|
}
|
|
|
|
/// <summary>The grate: a glowing plate just off the front face, a frame and bars in front of it.</summary>
|
|
private static Transform BuildGrate(Transform visual, Material iron, out Renderer glow)
|
|
{
|
|
Transform grate = new GameObject("grate").transform;
|
|
grate.SetParent(visual, false);
|
|
grate.gameObject.layer = visual.gameObject.layer;
|
|
|
|
Material bars = iron != null ? new Material(iron) { name = "AlfarFireChest_bars" } : null;
|
|
if (bars != null)
|
|
{
|
|
bars.SetTexture("_MainTex", null);
|
|
bars.color = new Color(0.16f, 0.15f, 0.15f);
|
|
}
|
|
|
|
glow = Block(grate, "glow", new Vector3(0f, GrateY, FrontZ + 0.005f), new Vector3(GrateWidth, GrateHeight, 0.01f), bars).GetComponent<Renderer>();
|
|
|
|
const float frame = 0.035f;
|
|
foreach (float x in new[] { -GrateWidth / 2f, GrateWidth / 2f })
|
|
Block(grate, "frame", new Vector3(x, GrateY, FrontZ + 0.02f), new Vector3(frame, GrateHeight + frame, 0.04f), bars);
|
|
foreach (float y in new[] { GrateY - GrateHeight / 2f, GrateY + GrateHeight / 2f })
|
|
Block(grate, "frame", new Vector3(0f, y, FrontZ + 0.02f), new Vector3(GrateWidth + frame, frame, 0.04f), bars);
|
|
|
|
for (int i = 1; i < GrateGaps; i++)
|
|
{
|
|
float x = -GrateWidth / 2f + GrateWidth * i / GrateGaps;
|
|
Block(grate, "bar", new Vector3(x, GrateY, FrontZ + 0.02f), new Vector3(0.022f, GrateHeight, 0.03f), bars);
|
|
}
|
|
Block(grate, "bar", new Vector3(0f, GrateY, FrontZ + 0.022f), new Vector3(GrateWidth, 0.022f, 0.03f), bars);
|
|
|
|
return grate;
|
|
}
|
|
|
|
/// <summary>A plain box with no collider, for trim the borrowed meshes do not have.</summary>
|
|
internal static GameObject Block(Transform parent, string name, Vector3 position, Vector3 size, Material material)
|
|
{
|
|
GameObject block = GameObject.CreatePrimitive(PrimitiveType.Cube);
|
|
Object.DestroyImmediate(block.GetComponent<Collider>());
|
|
block.name = name;
|
|
block.layer = parent.gameObject.layer;
|
|
block.transform.SetParent(parent, false);
|
|
block.transform.localPosition = position;
|
|
block.transform.localScale = size;
|
|
if (material != null) block.GetComponent<Renderer>().sharedMaterial = material;
|
|
return block;
|
|
}
|
|
|
|
/// <summary>The carried torch's embers, rising off the top of the grate.</summary>
|
|
private static ParticleSystem AddEmbers(Transform grate)
|
|
{
|
|
GameObject torch = PrefabManager.Cache.GetPrefab<GameObject>(EmbersSource);
|
|
Transform source = torch != null ? torch.transform.Find("Embers") : null;
|
|
if (source == null)
|
|
{
|
|
Jotunn.Logger.LogWarning("[Alfar] No torch embers for the Eldividarkista; its grate glows without sparks.");
|
|
return null;
|
|
}
|
|
|
|
GameObject embers = Object.Instantiate(source.gameObject, grate, false);
|
|
embers.name = "embers";
|
|
embers.transform.localPosition = new Vector3(0f, GrateY + GrateHeight / 2f, FrontZ + 0.05f);
|
|
embers.transform.localRotation = Quaternion.identity;
|
|
return embers.GetComponent<ParticleSystem>();
|
|
}
|
|
}
|
|
}
|