Merge branch 'localisation' into localisation-turkish
79
JotunnModStub/Alfar/AlfarChestGlow.cs
Normal file
|
|
@ -0,0 +1,79 @@
|
|||
using UnityEngine;
|
||||
|
||||
namespace RacesOfValheim
|
||||
{
|
||||
/// <summary>
|
||||
/// The light on the two Alfar chests, which says whether the drones have work there: the fire
|
||||
/// chest's grate burns while it holds wood they may burn, the entry chest's inlay shines while it
|
||||
/// holds anything but the sigil. Every client asks its own copy of the inventory, which Container
|
||||
/// keeps in step with the ZDO, so nothing travels over the network for it.
|
||||
/// </summary>
|
||||
public class AlfarChestGlow : MonoBehaviour
|
||||
{
|
||||
public Renderer[] Glows;
|
||||
public ParticleSystem Embers;
|
||||
public Color GlowColor;
|
||||
public bool WoodOnly;
|
||||
|
||||
private Container m_container;
|
||||
private Material m_lit;
|
||||
private Material m_cold;
|
||||
private bool? m_shown;
|
||||
private float m_nextCheck;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
m_container = GetComponent<Container>();
|
||||
if (Glows == null || Glows.Length == 0 || Glows[0] == null) return;
|
||||
|
||||
m_cold = Glows[0].sharedMaterial;
|
||||
m_lit = new Material(m_cold) { name = m_cold.name + "_lit" };
|
||||
m_lit.color = Color.black;
|
||||
m_lit.EnableKeyword("_EMISSION");
|
||||
m_lit.SetColor("_EmissionColor", GlowColor);
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (Time.time < m_nextCheck) return;
|
||||
m_nextCheck = Time.time + 1f;
|
||||
|
||||
bool lit = HasWork();
|
||||
if (m_shown == lit) return;
|
||||
m_shown = lit;
|
||||
|
||||
if (m_lit != null)
|
||||
{
|
||||
foreach (Renderer glow in Glows)
|
||||
{
|
||||
if (glow != null) glow.sharedMaterial = lit ? m_lit : m_cold;
|
||||
}
|
||||
}
|
||||
if (Embers != null)
|
||||
{
|
||||
if (lit) Embers.Play(true);
|
||||
else Embers.Stop(true, ParticleSystemStopBehavior.StopEmitting);
|
||||
}
|
||||
}
|
||||
|
||||
private bool HasWork()
|
||||
{
|
||||
Inventory inventory = m_container != null ? m_container.GetInventory() : null;
|
||||
if (inventory == null) return false;
|
||||
|
||||
foreach (ItemDrop.ItemData item in inventory.GetAllItems())
|
||||
{
|
||||
if (item == null || item.m_dropPrefab == null) continue;
|
||||
|
||||
string name = item.m_dropPrefab.name;
|
||||
if (WoodOnly ? AlfarDroneAI.IsWood(name) : name != AlfarSigil.PrefabName) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
if (m_lit != null) Destroy(m_lit);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -61,12 +61,15 @@ namespace RacesOfValheim
|
|||
public static void Register()
|
||||
{
|
||||
RegisterOne(EntryName, "$rov_piece_alfar_inngangskista_name", "$rov_piece_alfar_inngangskista_desc",
|
||||
new Color(0.62f, 0.80f, 1f, 1f));
|
||||
"$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",
|
||||
new Color(0.85f, 0.62f, 0.36f, 1f));
|
||||
"$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, Color tint)
|
||||
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)
|
||||
|
|
@ -91,15 +94,19 @@ namespace RacesOfValheim
|
|||
}
|
||||
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 = display;
|
||||
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;
|
||||
|
||||
AlfarConstructs.Tint(prefab, tint);
|
||||
// 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
|
||||
{
|
||||
|
|
@ -107,7 +114,7 @@ namespace RacesOfValheim
|
|||
Description = description,
|
||||
PieceTable = PieceTables.Hammer,
|
||||
Category = PieceCategories.Crafting,
|
||||
Icon = piece.m_icon,
|
||||
Icon = icon,
|
||||
Requirements = requirements.ToArray(),
|
||||
}));
|
||||
|
||||
|
|
@ -130,5 +137,12 @@ namespace RacesOfValheim
|
|||
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -58,6 +58,13 @@ namespace RacesOfValheim
|
|||
public const string KeyStatus = "RoV_alfarStatus";
|
||||
public const string KeyDest = "RoV_alfarDest";
|
||||
|
||||
// What the drone last said: a counter every client watches, the text key and the item.
|
||||
// Each client builds the line in its own language, so only the token travels.
|
||||
public const string KeySaySeq = "RoV_alfarSaySeq";
|
||||
public const string KeySayKey = "RoV_alfarSayKey";
|
||||
public const string KeySayItem = "RoV_alfarSayItem";
|
||||
public const string KeySayStation = "RoV_alfarSayStation";
|
||||
|
||||
/// <summary>Every drone alive in the loaded zones: the repairs look at each other through it.</summary>
|
||||
public static readonly List<AlfarDroneAI> All = new List<AlfarDroneAI>();
|
||||
|
||||
|
|
@ -141,6 +148,7 @@ namespace RacesOfValheim
|
|||
|
||||
private float m_nextFightScan;
|
||||
private float m_fightUntil;
|
||||
private bool m_fighting;
|
||||
|
||||
private ZNetView m_nview;
|
||||
private Character m_character;
|
||||
|
|
@ -168,6 +176,11 @@ namespace RacesOfValheim
|
|||
private ZDOID m_sortDest;
|
||||
private float m_scannedAt = -99f;
|
||||
|
||||
// Speech: the last line this client showed, and when to look for a new one.
|
||||
private int m_heardSeq;
|
||||
private float m_nextListen;
|
||||
private float m_nextKilnCheck;
|
||||
|
||||
private Job m_job;
|
||||
private float m_nextPlan;
|
||||
private float m_jobDeadline;
|
||||
|
|
@ -200,6 +213,16 @@ namespace RacesOfValheim
|
|||
|
||||
All.Add(this);
|
||||
ReadPayload();
|
||||
|
||||
// A line said before this object loaded is old news: do not replay it on a zone reload.
|
||||
if (m_nview != null && m_nview.IsValid()) m_heardSeq = m_nview.GetZDO().GetInt(KeySaySeq, 0);
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (Time.time < m_nextListen) return;
|
||||
m_nextListen = Time.time + 0.5f;
|
||||
Listen();
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
|
|
@ -293,7 +316,17 @@ namespace RacesOfValheim
|
|||
if (!m_fightsBack || m_ai == null || m_character == null || m_character.IsDead()) return false;
|
||||
if (m_nview == null || !m_nview.IsValid() || !m_nview.IsOwner()) return false;
|
||||
|
||||
// A tamed MonsterAI with no patrol point and no follow target never drops its target for
|
||||
// distance (UpdateTarget, IL): only after 30 s unsensed or 60 s without a swing. The drone
|
||||
// hears far, so an enemy that ran off kept "being sensed" and held the tick for vanilla.
|
||||
// Past the leash it is no longer this drone's fight.
|
||||
Character target = m_ai.GetTargetCreature();
|
||||
if (target != null && !target.IsDead() && !InFightReach(target))
|
||||
{
|
||||
m_ai.MakeTame();
|
||||
target = null;
|
||||
}
|
||||
|
||||
if (target != null && !target.IsDead())
|
||||
{
|
||||
m_fightUntil = Time.time + FightLinger;
|
||||
|
|
@ -311,14 +344,33 @@ namespace RacesOfValheim
|
|||
}
|
||||
}
|
||||
|
||||
if (Time.time >= m_fightUntil) return false;
|
||||
if (Time.time >= m_fightUntil)
|
||||
{
|
||||
// The fight is over: clear what vanilla still holds (target, alert), or the next
|
||||
// GetTargetCreature hands the tick straight back to it. MakeTame is the public door
|
||||
// that nulls both targets and the alert in one call; the drone is tamed already.
|
||||
if (m_fighting) { m_fighting = false; m_ai.MakeTame(); }
|
||||
return false;
|
||||
}
|
||||
|
||||
m_fighting = true;
|
||||
m_job = null;
|
||||
m_nextPlan = 0f; // the fight moved it; plan afresh the moment it hands back
|
||||
SetStatus("Fighting.");
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>Close to the drone, and not past the edge of the base it works.</summary>
|
||||
private bool InFightReach(Character enemy)
|
||||
{
|
||||
Vector3 at = enemy.transform.position;
|
||||
if (Vector3.Distance(at, transform.position) > FightRange * 2f) return false;
|
||||
|
||||
Vector3? anchor = Anchor;
|
||||
float leash = AlfarNexusConfig.NexusRadius.Value + m_radiusBonus + FightRange;
|
||||
return anchor == null || Vector3.Distance(at, anchor.Value) <= leash;
|
||||
}
|
||||
|
||||
// ================================================================ the tick
|
||||
|
||||
/// <summary>Everything. Returns what MonsterAI.UpdateAI would have returned.</summary>
|
||||
|
|
@ -393,6 +445,7 @@ namespace RacesOfValheim
|
|||
|
||||
Scan(anchor.Value);
|
||||
ExpirePenalties();
|
||||
CheckIdleKiln();
|
||||
|
||||
// A harvest is in progress: wait for the drops to land, then gather them and replant.
|
||||
if (m_farmSpot != null)
|
||||
|
|
@ -1422,16 +1475,25 @@ namespace RacesOfValheim
|
|||
if (inventory == null) return null;
|
||||
|
||||
string sigil = AlfarSigil.PrefabName;
|
||||
bool spoke = false;
|
||||
foreach (ItemDrop.ItemData item in inventory.GetAllItems())
|
||||
{
|
||||
if (item == null || item.m_dropPrefab == null) continue;
|
||||
|
||||
string name = item.m_dropPrefab.name;
|
||||
if (name == sigil) continue;
|
||||
if (!IsWood(name) && AnyStationAccepts(name)) continue;
|
||||
if (!IsWood(name) && AnyStationAccepts(name))
|
||||
{
|
||||
if (!spoke) spoke = Say("rov_msg_alfar_drone_sort_keep", name, KeepRepeatSeconds);
|
||||
continue;
|
||||
}
|
||||
|
||||
Container destination = DestinationFor(name);
|
||||
if (destination == null) continue;
|
||||
if (destination == null)
|
||||
{
|
||||
if (!spoke) spoke = Say("rov_msg_alfar_drone_sort_nowhere", name, NowhereRepeatSeconds);
|
||||
continue;
|
||||
}
|
||||
|
||||
m_sortItem = name;
|
||||
m_sortDest = ZdoOf(destination);
|
||||
|
|
@ -1447,6 +1509,119 @@ namespace RacesOfValheim
|
|||
return null;
|
||||
}
|
||||
|
||||
// ================================================================ speech
|
||||
|
||||
/// <summary>When each item may be mentioned again, shared by every drone on this client, so
|
||||
/// five drones looking at the same stone say it once and not five times.</summary>
|
||||
private static readonly Dictionary<string, float> s_nextMention = new Dictionary<string, float>();
|
||||
private const float NowhereRepeatSeconds = 300f;
|
||||
private const float KeepRepeatSeconds = 1800f;
|
||||
private const float SpeechRange = 40f;
|
||||
|
||||
/// <summary>Owner side: says the line once per cooldown per item, by writing it into the ZDO
|
||||
/// where every client in range picks it up. Returns whether it spoke, so one plan says one
|
||||
/// line and the bubbles do not overwrite each other.</summary>
|
||||
private bool Say(string key, string item, float repeatSeconds, string station = "")
|
||||
{
|
||||
string mention = key + "|" + item;
|
||||
float next;
|
||||
if (s_nextMention.TryGetValue(mention, out next) && Time.time < next) return false;
|
||||
s_nextMention[mention] = Time.time + repeatSeconds;
|
||||
|
||||
ZDO zdo = m_nview.GetZDO();
|
||||
zdo.Set(KeySayKey, key);
|
||||
zdo.Set(KeySayItem, item);
|
||||
zdo.Set(KeySayStation, station);
|
||||
zdo.Set(KeySaySeq, zdo.GetInt(KeySaySeq, 0) + 1);
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>Every client: a new line in the ZDO goes over the drone's head, the way vanilla's
|
||||
/// NPCs talk, and into the chat window, for players close enough to care.</summary>
|
||||
private void Listen()
|
||||
{
|
||||
if (m_nview == null || !m_nview.IsValid()) return;
|
||||
|
||||
ZDO zdo = m_nview.GetZDO();
|
||||
int seq = zdo.GetInt(KeySaySeq, 0);
|
||||
if (seq == m_heardSeq) return;
|
||||
m_heardSeq = seq;
|
||||
|
||||
Player player = Player.m_localPlayer;
|
||||
if (player == null || Chat.instance == null) return;
|
||||
if (Vector3.Distance(player.transform.position, transform.position) > SpeechRange) return;
|
||||
|
||||
string item = zdo.GetString(KeySayItem, "");
|
||||
GameObject prefab = ObjectDB.instance != null ? ObjectDB.instance.GetItemPrefab(item) : null;
|
||||
ItemDrop drop = prefab != null ? prefab.GetComponent<ItemDrop>() : null;
|
||||
string itemName = drop != null ? drop.m_itemData.m_shared.m_name : item;
|
||||
|
||||
string text = ModText.Get(zdo.GetString(KeySayKey, ""), itemName,
|
||||
"$rov_piece_alfar_inngangskista_name", "$rov_piece_alfar_eldividarkista_name",
|
||||
zdo.GetString(KeySayStation, ""));
|
||||
string speaker = m_character != null ? Localization.instance.Localize(m_character.m_name) : "";
|
||||
|
||||
Chat.instance.SetNpcText(gameObject, Vector3.up * 1.5f, SpeechRange, 8f, speaker, text, false);
|
||||
Chat.instance.AddString(speaker, text, Talker.Type.Normal);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The mistake players make with the kiln: the wood is in a plain chest (vanilla even calls
|
||||
/// one "Wood chest"), and only the Eldividarkista's wood is ever burnt. A station that takes
|
||||
/// wood, standing idle with nothing for it in the Eldividarkista while the right wood sits in
|
||||
/// another chest, gets a line explaining that. Every 30 s is plenty for something the player
|
||||
/// fixes by hand.
|
||||
/// </summary>
|
||||
private void CheckIdleKiln()
|
||||
{
|
||||
if (Time.time < m_nextKilnCheck) return;
|
||||
m_nextKilnCheck = Time.time + 30f;
|
||||
|
||||
foreach (ButlerStation station in m_stations)
|
||||
{
|
||||
if (!station.Alive || !station.Operable || station.HasWork || station.FreeSlots <= 0) continue;
|
||||
if (m_wood != null && FirstAccepted(station, m_wood) != null) continue;
|
||||
|
||||
string misplaced = WoodElsewhereFor(station);
|
||||
if (misplaced == null) continue;
|
||||
|
||||
// The station's own name token, so every language says "kiln" the game's way.
|
||||
Piece piece = station.Behaviour.GetComponent<Piece>();
|
||||
string stationName = piece != null ? piece.m_name : "";
|
||||
if (Say("rov_msg_alfar_drone_kiln_wood", misplaced, NowhereRepeatSeconds, stationName)) return;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Wood the station would take, lying in the entry chest or a storage chest.</summary>
|
||||
private string WoodElsewhereFor(ButlerStation station)
|
||||
{
|
||||
if (m_entry != null)
|
||||
{
|
||||
string found = WoodIn(m_entry, station);
|
||||
if (found != null) return found;
|
||||
}
|
||||
foreach (Container chest in m_chests)
|
||||
{
|
||||
string found = WoodIn(chest, station);
|
||||
if (found != null) return found;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static string WoodIn(Container chest, ButlerStation station)
|
||||
{
|
||||
Inventory inventory = chest != null ? chest.GetInventory() : null;
|
||||
if (inventory == null) return null;
|
||||
|
||||
foreach (ItemDrop.ItemData item in inventory.GetAllItems())
|
||||
{
|
||||
if (item == null || item.m_dropPrefab == null) continue;
|
||||
string name = item.m_dropPrefab.name;
|
||||
if (IsWood(name) && station.Accepts(name)) return name;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private bool DoSortFetch()
|
||||
{
|
||||
if (m_sortItem == null || m_sortDest == ZDOID.None) return false;
|
||||
|
|
@ -1467,6 +1642,72 @@ namespace RacesOfValheim
|
|||
// ================================================================ moving
|
||||
|
||||
/// <summary>Vanilla pathing, through the private MoveTo. True the moment it has arrived.</summary>
|
||||
/// <summary>F8 readout: what each worker within 60 m is doing and what vanilla still holds, and
|
||||
/// for the nearest one, why each thing in the entry chest is (or is not) being sorted.</summary>
|
||||
public static void DebugReport(Player player)
|
||||
{
|
||||
var lines = new List<string>();
|
||||
AlfarDroneAI nearest = null;
|
||||
float nearestDistance = 60f;
|
||||
|
||||
foreach (AlfarDroneAI drone in All)
|
||||
{
|
||||
if (drone == null || drone.m_ai == null) continue;
|
||||
float distance = Vector3.Distance(drone.transform.position, player.transform.position);
|
||||
if (distance > 60f) continue;
|
||||
if (distance < nearestDistance) { nearestDistance = distance; nearest = drone; }
|
||||
|
||||
Character target = drone.m_ai.GetTargetCreature();
|
||||
string targetText = target != null
|
||||
? $"{Utils.GetPrefabName(target.gameObject)} {Vector3.Distance(target.transform.position, drone.transform.position):0}m"
|
||||
: "none";
|
||||
lines.Add($"[RoV drone] {distance:0}m: '{drone.Status}' job {(drone.m_job != null ? drone.m_job.Kind : "none")} " +
|
||||
$"carry {drone.PayloadCount()} fight {drone.m_fighting} vanilla target {targetText} " +
|
||||
$"alerted {drone.m_ai.IsAlerted()} flying {drone.m_character.IsFlying()} owner {drone.m_nview.IsOwner()}");
|
||||
}
|
||||
|
||||
if (nearest == null) lines.Add("[RoV drone] no worker drone within 60m");
|
||||
else lines.AddRange(nearest.SortReport());
|
||||
|
||||
foreach (string line in lines)
|
||||
{
|
||||
Debug.Log(line);
|
||||
player.Message(MessageHud.MessageType.TopLeft, line);
|
||||
}
|
||||
}
|
||||
|
||||
private IEnumerable<string> SortReport()
|
||||
{
|
||||
if (m_entry == null) { yield return "[RoV sort] no entry chest in range"; yield break; }
|
||||
if (m_entry.IsInUse()) yield return "[RoV sort] entry chest is open";
|
||||
if (IsPenalised(ZdoOf(m_entry))) yield return "[RoV sort] entry chest is set aside (penalty)";
|
||||
|
||||
Inventory inventory = m_entry.GetInventory();
|
||||
if (inventory == null) yield break;
|
||||
|
||||
var seen = new HashSet<string>();
|
||||
foreach (ItemDrop.ItemData item in inventory.GetAllItems())
|
||||
{
|
||||
if (item == null) continue;
|
||||
if (item.m_dropPrefab == null) { yield return $"[RoV sort] {item.m_shared.m_name}: no drop prefab"; continue; }
|
||||
|
||||
string name = item.m_dropPrefab.name;
|
||||
if (!seen.Add(name)) continue;
|
||||
|
||||
string verdict;
|
||||
if (name == AlfarSigil.PrefabName) verdict = "sigil, stays";
|
||||
else if (!IsWood(name) && AnyStationAccepts(name)) verdict = "a station takes it, stays as work";
|
||||
else
|
||||
{
|
||||
Container destination = DestinationFor(name);
|
||||
verdict = destination != null
|
||||
? $"goes to chest at {Vector3.Distance(destination.transform.position, m_entry.transform.position):0}m"
|
||||
: $"nowhere: no storage chest holds it and none is empty ({m_chests.Count} chests)";
|
||||
}
|
||||
yield return $"[RoV sort] {name}: {verdict}";
|
||||
}
|
||||
}
|
||||
|
||||
private bool MoveToPoint(float dt, Vector3 point, float distance, bool run)
|
||||
{
|
||||
if (m_ai == null || MoveToMethod == null) return true; // cannot walk: act in place
|
||||
|
|
@ -1637,7 +1878,7 @@ namespace RacesOfValheim
|
|||
"Wood", "FineWood", "RoundLog", "ElderBark", "YggdrasilWood", "Blackwood",
|
||||
};
|
||||
|
||||
private static bool IsWood(string prefabName) => s_woodFamily.Contains(prefabName);
|
||||
internal static bool IsWood(string prefabName) => s_woodFamily.Contains(prefabName);
|
||||
|
||||
/// <summary>
|
||||
/// The first thing a station will take, and the chest it is in: raw material from the ENTRY chest
|
||||
|
|
|
|||
166
JotunnModStub/Alfar/AlfarFireChest.cs
Normal file
|
|
@ -0,0 +1,166 @@
|
|||
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>();
|
||||
}
|
||||
}
|
||||
}
|
||||
137
JotunnModStub/Alfar/AlfarInputChest.cs
Normal file
|
|
@ -0,0 +1,137 @@
|
|||
using System.Collections.Generic;
|
||||
using Jotunn.Managers;
|
||||
using UnityEngine;
|
||||
|
||||
namespace RacesOfValheim
|
||||
{
|
||||
/// <summary>
|
||||
/// The Inngangskista's own body, the cold twin of <see cref="AlfarFireChest"/>: the dvergr loot
|
||||
/// chest of the Mistlands towns (seen, never built), its panels repainted navy steel
|
||||
/// (scripts/paint_input_chest.py) and its copper trim turned silver. A cyan line set into the
|
||||
/// lid shines while the chest holds anything for the drones, and goes dark once they have
|
||||
/// emptied it.
|
||||
/// </summary>
|
||||
public static class AlfarInputChest
|
||||
{
|
||||
private const string SourceName = "TreasureChest_dvergrtown";
|
||||
|
||||
// The town chest is placed at 1.2 and its meshes at 1.5 on top: 1.66 m wide, a vanilla chest's size.
|
||||
private const float SourceScale = 1.2f;
|
||||
private const float MeshScale = 1.5f * SourceScale;
|
||||
private const float LidTop = 0.48f * MeshScale;
|
||||
private const float LidHalfX = 0.42f * MeshScale;
|
||||
private const float LidHalfZ = 0.24f * MeshScale;
|
||||
private const float InlayInset = 0.10f;
|
||||
private const float InlayWidth = 0.03f;
|
||||
|
||||
private static readonly Color Trim = new Color(0.9f, 0.95f, 1f);
|
||||
private static readonly Color Inlay = new Color(0.35f, 0.9f, 1f);
|
||||
|
||||
/// <summary>Swaps the cloned wood chest's meshes for the input chest. False leaves the wood
|
||||
/// chest's look in place, with a warning.</summary>
|
||||
public static bool Build(GameObject prefab)
|
||||
{
|
||||
GameObject source = PrefabManager.Cache.GetPrefab<GameObject>(SourceName);
|
||||
Transform sourceNew = source != null ? source.transform.Find("New") : null;
|
||||
Transform box = sourceNew != null ? sourceNew.Find("stonechest") : null;
|
||||
Transform closed = sourceNew != null ? sourceNew.Find("stonechesttop_closed") : null;
|
||||
Transform open = sourceNew != null ? sourceNew.Find("stonechesttop_open") : null;
|
||||
Transform visual = prefab.transform.Find("New");
|
||||
if (box == null || closed == null || open == null || visual == null)
|
||||
{
|
||||
Jotunn.Logger.LogWarning("[Alfar] No dvergr chest to build the Inngangskista from; it keeps the wood chest's look.");
|
||||
return false;
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
GameObject body = Copy(box, visual, "body");
|
||||
GameObject lidClosed = Copy(closed, visual, "lid_closed");
|
||||
GameObject lidOpen = Copy(open, visual, "lid_open");
|
||||
lidOpen.SetActive(false);
|
||||
|
||||
Container container = prefab.GetComponent<Container>();
|
||||
if (container != null)
|
||||
{
|
||||
container.m_open = lidOpen;
|
||||
container.m_closed = lidClosed;
|
||||
}
|
||||
|
||||
Texture2D paint = PieceLook.LoadTexture("AlfarInputChest_d.png");
|
||||
if (paint == null) return true; // the dvergr chest as it is: still not a vanilla chest
|
||||
PieceLook.Retexture(visual, new Dictionary<string, Texture> { { "dvergrchestWorn_d", paint } });
|
||||
|
||||
// The trim shares the anvil's texture, so it is recoloured on a copy instead; the panels'
|
||||
// material is already a copy from Retexture.
|
||||
var copies = new Dictionary<Material, Material>();
|
||||
Material panel = null;
|
||||
foreach (Renderer renderer in visual.GetComponentsInChildren<Renderer>(true))
|
||||
{
|
||||
Material[] materials = renderer.sharedMaterials;
|
||||
for (int i = 0; i < materials.Length; i++)
|
||||
{
|
||||
Material material = materials[i];
|
||||
if (material == null) continue;
|
||||
if (material.name.EndsWith("_rov")) { panel = panel ?? material; continue; }
|
||||
if (!material.name.StartsWith("dvergr_metal_furnmiture")) continue;
|
||||
|
||||
if (!copies.TryGetValue(material, out Material trim))
|
||||
{
|
||||
trim = new Material(material) { name = material.name + "_rov" };
|
||||
trim.color = Trim;
|
||||
if (trim.HasProperty("_MetalColor")) trim.SetColor("_MetalColor", Trim);
|
||||
copies[material] = trim;
|
||||
}
|
||||
materials[i] = trim;
|
||||
}
|
||||
renderer.sharedMaterials = materials;
|
||||
}
|
||||
|
||||
AlfarChestGlow look = prefab.AddComponent<AlfarChestGlow>();
|
||||
look.Glows = BuildInlay(lidClosed.transform, panel);
|
||||
look.GlowColor = Inlay * 1.6f;
|
||||
look.WoodOnly = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>A copy of one of the town chest's parts, at the town chest's size and on the piece layer.</summary>
|
||||
private static GameObject Copy(Transform part, Transform parent, string name)
|
||||
{
|
||||
GameObject copy = Object.Instantiate(part.gameObject, parent, false);
|
||||
copy.name = name;
|
||||
copy.transform.localPosition = part.localPosition * SourceScale;
|
||||
copy.transform.localScale = part.localScale * SourceScale;
|
||||
foreach (Transform t in copy.GetComponentsInChildren<Transform>(true)) t.gameObject.layer = parent.gameObject.layer;
|
||||
return copy;
|
||||
}
|
||||
|
||||
/// <summary>The cyan line on the lid: four thin strips just above it, inset from the edge. They
|
||||
/// hang off the closed lid, so they go with it when the chest opens. The lid is scaled, so the
|
||||
/// sizes are divided back out of it.</summary>
|
||||
private static Renderer[] BuildInlay(Transform lid, Material panel)
|
||||
{
|
||||
Material cold = panel != null ? new Material(panel) { name = "AlfarInputChest_inlay" } : null;
|
||||
if (cold != null)
|
||||
{
|
||||
cold.SetTexture("_MainTex", null);
|
||||
cold.color = new Color(0.08f, 0.12f, 0.16f);
|
||||
}
|
||||
|
||||
float k = 1f / lid.localScale.x;
|
||||
float x = LidHalfX - InlayInset, z = LidHalfZ - InlayInset, y = LidTop + 0.004f;
|
||||
var strips = new List<Renderer>();
|
||||
foreach (float side in new[] { -z, z })
|
||||
strips.Add(Strip(lid, new Vector3(0f, y, side) * k, new Vector3(2f * x + InlayWidth, 0.01f, InlayWidth) * k, cold));
|
||||
foreach (float side in new[] { -x, x })
|
||||
strips.Add(Strip(lid, new Vector3(side, y, 0f) * k, new Vector3(InlayWidth, 0.01f, 2f * z) * k, cold));
|
||||
return strips.ToArray();
|
||||
}
|
||||
|
||||
private static Renderer Strip(Transform lid, Vector3 position, Vector3 size, Material material)
|
||||
{
|
||||
return AlfarFireChest.Block(lid, "inlay", position, size, material).GetComponent<Renderer>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -46,7 +46,9 @@ namespace RacesOfValheim
|
|||
Object.DestroyImmediate(behaviour);
|
||||
}
|
||||
|
||||
AlfarConstructs.Tint(prefab, new Color(0.62f, 0.8f, 1f, 1f));
|
||||
// The floating pyramid; the blue table stays as the fallback if it cannot be built.
|
||||
bool pyramid = AlfarNexusLook.Build(prefab);
|
||||
if (!pyramid) AlfarConstructs.Tint(prefab, new Color(0.62f, 0.8f, 1f, 1f));
|
||||
|
||||
AlfarNexusBehaviour nexus = prefab.AddComponent<AlfarNexusBehaviour>();
|
||||
nexus.m_switch = prefab.AddComponent<Switch>();
|
||||
|
|
@ -71,7 +73,7 @@ namespace RacesOfValheim
|
|||
trader.m_randomUseItemAlreadyRecieved = new List<string>();
|
||||
trader.m_randomTalkConditionals = new List<Trader.ConditionalDialog>();
|
||||
|
||||
Sprite icon = BorrowIcon("Eitr") ?? BorrowIcon("SurtlingCore");
|
||||
Sprite icon = (pyramid ? AlfarChests.IconFrom("AlfarNexus_icon.png") : null) ?? BorrowIcon("Eitr") ?? BorrowIcon("SurtlingCore");
|
||||
|
||||
Piece piece = prefab.GetComponent<Piece>() ?? prefab.AddComponent<Piece>();
|
||||
piece.m_craftingStation = null;
|
||||
|
|
|
|||
217
JotunnModStub/Alfar/AlfarNexusLook.cs
Normal file
|
|
@ -0,0 +1,217 @@
|
|||
using Jotunn.Managers;
|
||||
using UnityEngine;
|
||||
|
||||
namespace RacesOfValheim
|
||||
{
|
||||
/// <summary>
|
||||
/// The Ljoskjarne's body: a stone pyramid, 2 m to a side and 2 m tall, floating 0.8 m above the
|
||||
/// ground. Dark steel carved with Valheim's own runes (the Ashlands rune tile's glyphs, laid out by
|
||||
/// scripts/paint_nexus.py), and a cyan seam down the middle of each face.
|
||||
///
|
||||
/// The seam is painted into the faces' glow map, not built. Bars standing on the faces, lit or
|
||||
/// unlit, lost part of their length to the face on whichever side looked one way in the world,
|
||||
/// as the pyramid turned; a line in the face's own pixels has nothing to hide behind.
|
||||
///
|
||||
/// Only the look moves. The piece keeps one still collider from the ground up, so building on it,
|
||||
/// support, hovering and the E key behave as before; the pyramid bobs and turns on each client by
|
||||
/// itself, nothing over the network. The seam breathes, and burns brighter while crystals wait.
|
||||
/// </summary>
|
||||
public static class AlfarNexusLook
|
||||
{
|
||||
private const float Height = 2f;
|
||||
private const float HalfBase = 1f;
|
||||
private const float Lift = 0.8f;
|
||||
private const string SourceMaterialPrefab = "piece_cartographytable";
|
||||
private const string EmbersSource = "fx_Torch_Carried";
|
||||
|
||||
private static readonly Color Seam = new Color(0.35f, 0.75f, 1f);
|
||||
|
||||
/// <summary>Strips the cartography table's body and puts the pyramid in its place. False leaves
|
||||
/// the table, with a warning, so the Nexus is never invisible.</summary>
|
||||
public static bool Build(GameObject prefab)
|
||||
{
|
||||
Texture2D face = PieceLook.LoadTexture("AlfarNexus_face.png");
|
||||
Texture2D glow = PieceLook.LoadTexture("AlfarNexus_glow.png");
|
||||
Texture2D bumps = PieceLook.LoadTexture("AlfarNexus_n.png", true);
|
||||
Renderer tableRenderer = prefab.transform.Find("new/high")?.GetComponent<Renderer>();
|
||||
if (face == null || glow == null || tableRenderer == null || tableRenderer.sharedMaterial == null)
|
||||
{
|
||||
Jotunn.Logger.LogWarning("[Alfar] Could not build the Ljoskjarne's pyramid; it keeps the cartography table's look.");
|
||||
return false;
|
||||
}
|
||||
|
||||
Material stone = new Material(tableRenderer.sharedMaterial) { name = "AlfarNexus_stone" };
|
||||
stone.color = Color.white;
|
||||
stone.SetTexture("_MainTex", face);
|
||||
// Forged, not polished: the plate's own grain in the normal map, and a dull sheen.
|
||||
stone.SetTexture("_BumpMap", bumps);
|
||||
if (bumps != null) stone.EnableKeyword("_NORMALMAP");
|
||||
else stone.DisableKeyword("_NORMALMAP");
|
||||
if (stone.HasProperty("_MetallicGlossMap")) stone.SetTexture("_MetallicGlossMap", null);
|
||||
if (stone.HasProperty("_Metallic")) stone.SetFloat("_Metallic", 0.6f);
|
||||
if (stone.HasProperty("_Glossiness")) stone.SetFloat("_Glossiness", 0.3f);
|
||||
// Custom/Piece samples its noise in world space unless told the object moves, as boats and
|
||||
// carts do; on a turning pyramid the blotches would slide across the faces.
|
||||
stone.EnableKeyword("_MOVEABLEOBJECT_ON");
|
||||
if (stone.HasProperty("_MoveableObject")) stone.SetFloat("_MoveableObject", 1f);
|
||||
stone.SetTexture("_EmissionMap", glow);
|
||||
stone.EnableKeyword("_EMISSION");
|
||||
stone.SetColor("_EmissionColor", Seam);
|
||||
|
||||
// The table goes whole: its meshes, its damage states, its fragments and its four colliders.
|
||||
for (int i = prefab.transform.childCount - 1; i >= 0; i--)
|
||||
Object.DestroyImmediate(prefab.transform.GetChild(i).gameObject);
|
||||
WearNTear wear = prefab.GetComponent<WearNTear>();
|
||||
if (wear != null)
|
||||
{
|
||||
wear.m_new = null;
|
||||
wear.m_worn = null;
|
||||
wear.m_broken = null;
|
||||
wear.m_fragmentRoots = new GameObject[0];
|
||||
}
|
||||
|
||||
// One still collider, from the ground to the tip, a little inside the faces.
|
||||
GameObject solid = new GameObject("collider") { layer = prefab.layer };
|
||||
solid.transform.SetParent(prefab.transform, false);
|
||||
BoxCollider box = solid.AddComponent<BoxCollider>();
|
||||
box.center = new Vector3(0f, (Lift + Height) / 2f, 0f);
|
||||
box.size = new Vector3(HalfBase * 1.4f, Lift + Height, HalfBase * 1.4f);
|
||||
|
||||
Transform floating = new GameObject("float").transform;
|
||||
floating.SetParent(prefab.transform, false);
|
||||
floating.gameObject.layer = prefab.layer;
|
||||
|
||||
MeshRenderer pyramid = Part(floating, "pyramid", PyramidMesh(), stone).GetComponent<MeshRenderer>();
|
||||
|
||||
NexusLook look = prefab.AddComponent<NexusLook>();
|
||||
look.Float = floating;
|
||||
look.SeamRenderer = pyramid;
|
||||
look.Motes = AddMotes(prefab.transform);
|
||||
return true;
|
||||
}
|
||||
|
||||
private static GameObject Part(Transform parent, string name, Mesh mesh, Material material)
|
||||
{
|
||||
GameObject part = new GameObject(name) { layer = parent.gameObject.layer };
|
||||
part.transform.SetParent(parent, false);
|
||||
part.AddComponent<MeshFilter>().sharedMesh = mesh;
|
||||
part.AddComponent<MeshRenderer>().sharedMaterial = material;
|
||||
return part;
|
||||
}
|
||||
|
||||
private static Vector3 Apex => new Vector3(0f, Lift + Height, 0f);
|
||||
|
||||
private static Vector3[] BaseCorners => new[]
|
||||
{
|
||||
new Vector3(-HalfBase, Lift, -HalfBase), new Vector3(HalfBase, Lift, -HalfBase),
|
||||
new Vector3(HalfBase, Lift, HalfBase), new Vector3(-HalfBase, Lift, HalfBase),
|
||||
};
|
||||
|
||||
/// <summary>Four faces, each with its own three corners so the shading stays flat and every face
|
||||
/// shows the whole carving (u along the base, v = 1 at the tip), and the underside.</summary>
|
||||
private static Mesh PyramidMesh()
|
||||
{
|
||||
Vector3[] c = BaseCorners;
|
||||
var vertices = new Vector3[16];
|
||||
var uvs = new Vector2[16];
|
||||
var triangles = new int[18];
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
// Wound clockwise seen from outside, which is Unity's front face.
|
||||
vertices[i * 3] = c[(i + 1) % 4];
|
||||
vertices[i * 3 + 1] = c[i];
|
||||
vertices[i * 3 + 2] = Apex;
|
||||
uvs[i * 3] = new Vector2(1f, 0f);
|
||||
uvs[i * 3 + 1] = new Vector2(0f, 0f);
|
||||
uvs[i * 3 + 2] = new Vector2(0.5f, 1f);
|
||||
triangles[i * 3] = i * 3;
|
||||
triangles[i * 3 + 1] = i * 3 + 1;
|
||||
triangles[i * 3 + 2] = i * 3 + 2;
|
||||
}
|
||||
for (int i = 0; i < 4; i++) { vertices[12 + i] = c[i]; uvs[12 + i] = new Vector2(0.1f, 0.02f); }
|
||||
int[] under = { 12, 13, 14, 12, 14, 15 };
|
||||
System.Array.Copy(under, 0, triangles, 12, 6);
|
||||
|
||||
Mesh mesh = new Mesh { name = "AlfarNexus_pyramid", vertices = vertices, uv = uvs, triangles = triangles };
|
||||
mesh.RecalculateNormals();
|
||||
mesh.RecalculateBounds();
|
||||
return mesh;
|
||||
}
|
||||
|
||||
/// <summary>A few cyan motes drifting up from the ground under it: the torch's embers, recoloured,
|
||||
/// spread over the pyramid's shadow and slowed down.</summary>
|
||||
private static ParticleSystem AddMotes(Transform root)
|
||||
{
|
||||
GameObject torch = PrefabManager.Cache.GetPrefab<GameObject>(EmbersSource);
|
||||
Transform source = torch != null ? torch.transform.Find("Embers") : null;
|
||||
if (source == null) return null;
|
||||
|
||||
GameObject motes = Object.Instantiate(source.gameObject, root, false);
|
||||
motes.name = "motes";
|
||||
motes.transform.localPosition = new Vector3(0f, 0.05f, 0f);
|
||||
motes.transform.localRotation = Quaternion.identity;
|
||||
PieceLook.Rehue(motes.transform, Seam * 2f);
|
||||
|
||||
ParticleSystem particles = motes.GetComponent<ParticleSystem>();
|
||||
if (particles != null)
|
||||
{
|
||||
ParticleSystem.ShapeModule shape = particles.shape;
|
||||
shape.enabled = true;
|
||||
shape.shapeType = ParticleSystemShapeType.Circle;
|
||||
shape.radius = HalfBase;
|
||||
shape.rotation = new Vector3(-90f, 0f, 0f);
|
||||
ParticleSystem.MainModule main = particles.main;
|
||||
main.simulationSpeed = 0.5f;
|
||||
}
|
||||
return particles;
|
||||
}
|
||||
|
||||
/// <summary>The motion and the seam's light, per client.</summary>
|
||||
public class NexusLook : MonoBehaviour
|
||||
{
|
||||
public Transform Float;
|
||||
public Renderer SeamRenderer;
|
||||
public ParticleSystem Motes;
|
||||
|
||||
private const float BobHeight = 0.08f;
|
||||
private const float BobSeconds = 4.5f;
|
||||
private const float TurnSeconds = 40f;
|
||||
private const float BreathSeconds = 3.5f;
|
||||
|
||||
private AlfarNexusBehaviour m_nexus;
|
||||
private Material m_seam;
|
||||
private float m_phase;
|
||||
private float m_ready; // eases between 0 (no crystals) and 1, so the brightening is not a jump
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
m_nexus = GetComponent<AlfarNexusBehaviour>();
|
||||
if (SeamRenderer != null) m_seam = SeamRenderer.material; // this one's own copy, to animate
|
||||
// Two Nexuses side by side must not bob in step.
|
||||
m_phase = (Mathf.Abs(transform.position.x * 0.37f + transform.position.z * 0.71f)) % 10f;
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
float t = Time.time + m_phase;
|
||||
if (Float != null)
|
||||
{
|
||||
Float.localPosition = new Vector3(0f, Mathf.Sin(t * 2f * Mathf.PI / BobSeconds) * BobHeight, 0f);
|
||||
Float.localRotation = Quaternion.Euler(0f, t * 360f / TurnSeconds, 0f);
|
||||
}
|
||||
|
||||
if (m_seam == null) return;
|
||||
bool ready = m_nexus != null && m_nexus.Crystals > 0;
|
||||
m_ready = Mathf.MoveTowards(m_ready, ready ? 1f : 0f, Time.deltaTime * 0.5f);
|
||||
float breath = 0.75f + 0.25f * Mathf.Sin(t * 2f * Mathf.PI / BreathSeconds);
|
||||
Color glow = Seam * breath * Mathf.Lerp(1f, 2.2f, m_ready);
|
||||
m_seam.SetColor("_EmissionColor", glow);
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
if (m_seam != null) Destroy(m_seam);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
BIN
JotunnModStub/Assets/AlfarFireChest/AlfarFireChest_d.png
Normal file
|
After Width: | Height: | Size: 53 KiB |
BIN
JotunnModStub/Assets/AlfarFireChest/AlfarFireChest_icon.png
Normal file
|
After Width: | Height: | Size: 9.5 KiB |
BIN
JotunnModStub/Assets/AlfarInputChest/AlfarInputChest_d.png
Normal file
|
After Width: | Height: | Size: 8.1 KiB |
BIN
JotunnModStub/Assets/AlfarInputChest/AlfarInputChest_icon.png
Normal file
|
After Width: | Height: | Size: 9.7 KiB |
BIN
JotunnModStub/Assets/AlfarNexus/AlfarNexus_face.png
Normal file
|
After Width: | Height: | Size: 216 KiB |
BIN
JotunnModStub/Assets/AlfarNexus/AlfarNexus_glow.png
Normal file
|
After Width: | Height: | Size: 1.9 KiB |
BIN
JotunnModStub/Assets/AlfarNexus/AlfarNexus_icon.png
Normal file
|
After Width: | Height: | Size: 11 KiB |
BIN
JotunnModStub/Assets/AlfarNexus/AlfarNexus_n.png
Normal file
|
After Width: | Height: | Size: 259 KiB |
BIN
JotunnModStub/Assets/Hammers/ShrinkHammer_icon.png
Normal file
|
After Width: | Height: | Size: 14 KiB |
BIN
JotunnModStub/Assets/Hammers/TrolsHammer_icon.png
Normal file
|
After Width: | Height: | Size: 19 KiB |
BIN
JotunnModStub/Audio/trolsbuilding.ogg
Normal file
BIN
JotunnModStub/Audio/trolsdeath.ogg
Normal file
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"name": "RacesOfValheim",
|
||||
"description": "A Valheim mod that adds eleven custom playable races (Alfar, 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.6.5",
|
||||
"version_number": "1.6.6",
|
||||
"website_url": "",
|
||||
"dependencies": [
|
||||
"denikson-BepInExPack_Valheim-5.4.2333",
|
||||
|
|
|
|||
|
|
@ -125,6 +125,7 @@ namespace RacesOfValheim
|
|||
RaceMeleeReach.DebugOn = !RaceMeleeReach.DebugOn;
|
||||
__instance.Message(MessageHud.MessageType.TopLeft, $"[RoV reach] debug {(RaceMeleeReach.DebugOn ? "on" : "off")}");
|
||||
AlfarMiner.DebugReport(__instance);
|
||||
AlfarDroneAI.DebugReport(__instance);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ namespace RacesOfValheim
|
|||
{
|
||||
public const string PluginGUID = "com.nandor.racesofvalheim";
|
||||
public const string PluginName = "Races Of Valheim";
|
||||
public const string PluginVersion = "1.6.5";
|
||||
public const string PluginVersion = "1.6.6";
|
||||
|
||||
private readonly Harmony harmony = new Harmony(PluginGUID);
|
||||
|
||||
|
|
@ -47,6 +47,7 @@ namespace RacesOfValheim
|
|||
// Not a race either: a tool any race can craft, so it sits beside the vulture rather
|
||||
// than inside the alphabetical run above.
|
||||
TrolsHammerConfig.Bind(Config);
|
||||
ShrinkHammerConfig.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);
|
||||
|
|
@ -75,6 +76,9 @@ namespace RacesOfValheim
|
|||
PrefabManager.OnVanillaPrefabsAvailable += CreateAllModAssets;
|
||||
CommandManager.Instance.AddConsoleCommand(new ResetRaceCommand());
|
||||
CommandManager.Instance.AddConsoleCommand(new CheckProgressionCommand());
|
||||
CommandManager.Instance.AddConsoleCommand(new TrolSoundCommand("rovsnd1", TrolSounds.Death));
|
||||
CommandManager.Instance.AddConsoleCommand(new TrolSoundCommand("rovsnd2", TrolSounds.Building));
|
||||
StartCoroutine(TrolSounds.Load());
|
||||
CommandManager.Instance.AddConsoleCommand(new IncreaseProgressionCommand());
|
||||
CommandManager.Instance.AddConsoleCommand(new ResetProgressionCommand());
|
||||
CommandManager.Instance.AddConsoleCommand(new DumpDvergerCommand());
|
||||
|
|
@ -306,6 +310,7 @@ namespace RacesOfValheim
|
|||
AlfarRace.CreateModAssets();
|
||||
WarVultureItem.Register();
|
||||
TrolsHammerItem.Register();
|
||||
ShrinkHammerItem.Register();
|
||||
BoneServant.Register();
|
||||
}
|
||||
// --- RACE SELECTION UI ---
|
||||
|
|
|
|||
|
|
@ -57,6 +57,7 @@
|
|||
manager has no extra folder to flatten. Loaded by name: PieceLook.LoadTexture("CookCloth_d.png"). -->
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="Assets\**\*.png" LogicalName="%(Filename)%(Extension)" />
|
||||
<EmbeddedResource Include="Audio\*.ogg" LogicalName="%(Filename)%(Extension)" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
|
|||
211
JotunnModStub/ShrinkHammer/BuildScale.cs
Normal file
|
|
@ -0,0 +1,211 @@
|
|||
using BepInEx.Configuration;
|
||||
using HarmonyLib;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
|
||||
namespace RacesOfValheim
|
||||
{
|
||||
/// <summary>
|
||||
/// What both sizing hammers share: which size the hammer in hand builds at, Alt + scroll to
|
||||
/// change it, the size floating over the ghost, and the "Alt: Size" row in the bottom bar.
|
||||
///
|
||||
/// Trol's Hammer builds 1 to 3 times the vanilla size, the Shrink Hammer a quarter to 1. Each
|
||||
/// keeps its size in its own config entry, and the wheel writes that entry, so Configuration
|
||||
/// Manager and the wheel never disagree. The entries are not synced: each player picks their own.
|
||||
/// Alt is free in build mode: vanilla's own placing modifier ("AltPlace") is Left Shift.
|
||||
/// </summary>
|
||||
public static class BuildScale
|
||||
{
|
||||
public const float Step = 0.05f;
|
||||
|
||||
/// <summary>The config entry behind the hammer in hand, or null for any other tool.</summary>
|
||||
public static ConfigEntry<float> EntryFor(ItemDrop.ItemData item)
|
||||
{
|
||||
if (TrolsHammerItem.IsTrolsHammer(item)) return TrolsHammerConfig.ScaleFactor;
|
||||
if (ShrinkHammerItem.IsShrinkHammer(item)) return ShrinkHammerConfig.ScaleFactor;
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>The multiplier a placement with this item in hand gets: 1 for any other tool.</summary>
|
||||
public static float For(ItemDrop.ItemData item)
|
||||
{
|
||||
if (TrolsHammerItem.IsTrolsHammer(item)) return TrolsHammerConfig.ActiveFactor();
|
||||
if (ShrinkHammerItem.IsShrinkHammer(item)) return ShrinkHammerConfig.ActiveFactor();
|
||||
return 1f;
|
||||
}
|
||||
|
||||
public static bool AltHeld() => Input.GetKey(KeyCode.LeftAlt) || Input.GetKey(KeyCode.RightAlt);
|
||||
|
||||
/// <summary>Moves the entry by whole steps, kept on the 0.05 grid and inside its range.</summary>
|
||||
public static void Nudge(ConfigEntry<float> entry, int steps)
|
||||
{
|
||||
AcceptableValueRange<float> range = entry.Description.AcceptableValues as AcceptableValueRange<float>;
|
||||
float min = range != null ? range.MinValue : 0.25f, max = range != null ? range.MaxValue : 3f;
|
||||
float value = Mathf.Round((entry.Value + steps * Step) / Step) * Step;
|
||||
entry.Value = Mathf.Clamp(value, min, max);
|
||||
}
|
||||
|
||||
// --- the size over the ghost ---
|
||||
|
||||
private static GameObject s_labelled;
|
||||
private static float s_shown;
|
||||
|
||||
/// <summary>
|
||||
/// The size in Valheim's own floating NPC text, with one of the two hammers in hand:
|
||||
/// - over the ghost, while the hammer's size differs from its default (1.2 for Trol's
|
||||
/// Hammer, 1 for the Shrink Hammer);
|
||||
/// - with the repair tool selected, over the piece aimed at, always: the size it was built
|
||||
/// at, 1 for a piece no sizing hammer built.
|
||||
/// The text has no timeout, so it is set again only when its piece or the size changes:
|
||||
/// setting it replays its fade-in.
|
||||
/// </summary>
|
||||
public static void UpdateLabel(Player player, GameObject ghost)
|
||||
{
|
||||
if (Chat.instance == null) return;
|
||||
|
||||
ConfigEntry<float> entry = player != null && player.InPlaceMode() ? EntryFor(player.RightItem) : null;
|
||||
if (entry == null)
|
||||
{
|
||||
ClearLabel();
|
||||
return;
|
||||
}
|
||||
|
||||
Piece tool = player.GetSelectedPiece();
|
||||
if (tool != null && tool.m_repairPiece)
|
||||
{
|
||||
Piece aimed = player.GetHoveringPiece();
|
||||
if (aimed != null) Show(aimed.gameObject, BuiltSize(aimed));
|
||||
else ClearLabel();
|
||||
return;
|
||||
}
|
||||
|
||||
float value = For(player.RightItem);
|
||||
if (ghost != null && ghost.activeInHierarchy && !Mathf.Approximately(value, (float)entry.DefaultValue))
|
||||
Show(ghost, value);
|
||||
else
|
||||
ClearLabel();
|
||||
}
|
||||
|
||||
/// <summary>The size a placed piece was built at, from its ZDO; 1 when no sizing hammer built it.</summary>
|
||||
private static float BuiltSize(Piece piece)
|
||||
{
|
||||
ZDO zdo = piece.GetComponent<ZNetView>()?.GetZDO();
|
||||
float saved = zdo != null ? zdo.GetFloat(TrolsHammerScaling.ScaleKey, 0f) : 0f;
|
||||
return saved > 0f ? saved : 1f;
|
||||
}
|
||||
|
||||
private static void Show(GameObject target, float value)
|
||||
{
|
||||
if (target == s_labelled && Mathf.Approximately(value, s_shown)) return;
|
||||
|
||||
ClearLabel();
|
||||
Chat.instance.SetNpcText(target, Vector3.up * (TopOf(target) + 0.3f), 30f, 0f, "",
|
||||
ModText.Get("rov_msg_build_scale", value.ToString("0.00")), false);
|
||||
s_labelled = target;
|
||||
s_shown = value;
|
||||
}
|
||||
|
||||
private static void ClearLabel()
|
||||
{
|
||||
if (s_labelled != null && Chat.instance != null) Chat.instance.ClearNpcText(s_labelled);
|
||||
s_labelled = null;
|
||||
}
|
||||
|
||||
/// <summary>How far above its pivot the ghost reaches, from its renderers.</summary>
|
||||
private static float TopOf(GameObject ghost)
|
||||
{
|
||||
float top = 0.5f;
|
||||
foreach (Renderer renderer in ghost.GetComponentsInChildren<Renderer>())
|
||||
top = Mathf.Max(top, renderer.bounds.max.y - ghost.transform.position.y);
|
||||
return top;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Alt + scroll in build mode. Vanilla turns the piece with the same wheel in the same method,
|
||||
/// whatever key is held, so the prefix reads the wheel for the size and the postfix puts the
|
||||
/// rotation back as it was.
|
||||
/// </summary>
|
||||
[HarmonyPatch(typeof(Player), "UpdatePlacement")]
|
||||
public static class BuildScaleScrollPatch
|
||||
{
|
||||
private static float s_scroll;
|
||||
|
||||
private static void Prefix(Player __instance, bool takeInput, int ___m_placeRotation, out int __state)
|
||||
{
|
||||
__state = ___m_placeRotation;
|
||||
if (!takeInput || __instance != Player.m_localPlayer || !__instance.InPlaceMode()) return;
|
||||
if (!BuildScale.AltHeld()) return;
|
||||
ConfigEntry<float> entry = BuildScale.EntryFor(__instance.RightItem);
|
||||
if (entry == null) return;
|
||||
|
||||
s_scroll += ZInput.GetMouseScrollWheel();
|
||||
if (s_scroll > __instance.m_scrollAmountThreshold) { s_scroll = 0f; BuildScale.Nudge(entry, 1); }
|
||||
if (s_scroll < -__instance.m_scrollAmountThreshold) { s_scroll = 0f; BuildScale.Nudge(entry, -1); }
|
||||
}
|
||||
|
||||
private static void Postfix(Player __instance, int __state, ref int ___m_placeRotation,
|
||||
ref float ___m_scrollCurrAmount, GameObject ___m_placementGhost)
|
||||
{
|
||||
if (__instance != Player.m_localPlayer) return;
|
||||
|
||||
if (BuildScale.AltHeld() && BuildScale.EntryFor(__instance.RightItem) != null)
|
||||
{
|
||||
___m_placeRotation = __state;
|
||||
___m_scrollCurrAmount = 0f;
|
||||
}
|
||||
BuildScale.UpdateLabel(__instance, ___m_placementGhost);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The "Alt: Size" row in the build hints, next to vanilla's "Rotate": a copy of that row (the
|
||||
/// wheel icon and its text), shown only while one of the two hammers is in hand. Added beside the
|
||||
/// vanilla rows rather than through Jotunn's key hints, which replace the whole bar for an item.
|
||||
/// </summary>
|
||||
[HarmonyPatch(typeof(KeyHints), "UpdateHints")]
|
||||
public static class BuildScaleKeyHintPatch
|
||||
{
|
||||
private static GameObject s_row;
|
||||
private static bool s_failed;
|
||||
|
||||
private static void Postfix(KeyHints __instance)
|
||||
{
|
||||
if (s_row == null && !s_failed) s_row = MakeRow(__instance);
|
||||
if (s_row == null) return;
|
||||
|
||||
Player player = Player.m_localPlayer;
|
||||
bool show = player != null && BuildScale.EntryFor(player.RightItem) != null;
|
||||
if (s_row.activeSelf != show) s_row.SetActive(show);
|
||||
}
|
||||
|
||||
private static GameObject MakeRow(KeyHints hints)
|
||||
{
|
||||
Transform rotate = hints.m_buildHints != null ? FindDeep(hints.m_buildHints.transform, "rotate") : null;
|
||||
TMP_Text source = rotate != null ? rotate.Find("Text")?.GetComponent<TMP_Text>() : null;
|
||||
if (source == null)
|
||||
{
|
||||
s_failed = true;
|
||||
Jotunn.Logger.LogWarning("[BuildScale] No rotate row in the build hints; the Alt: Size hint is not shown.");
|
||||
return null;
|
||||
}
|
||||
|
||||
GameObject row = Object.Instantiate(rotate.gameObject, rotate.parent, false);
|
||||
row.name = "RoV_scale";
|
||||
row.transform.SetSiblingIndex(rotate.GetSiblingIndex() + 1);
|
||||
row.transform.Find("Text").GetComponent<TMP_Text>().text = ModText.Get("rov_hint_build_scale");
|
||||
return row;
|
||||
}
|
||||
|
||||
private static Transform FindDeep(Transform parent, string name)
|
||||
{
|
||||
foreach (Transform child in parent)
|
||||
{
|
||||
if (child.name == name) return child;
|
||||
Transform found = FindDeep(child, name);
|
||||
if (found != null) return found;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
33
JotunnModStub/ShrinkHammer/ShrinkHammerConfig.cs
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
using BepInEx.Configuration;
|
||||
|
||||
namespace RacesOfValheim
|
||||
{
|
||||
/// <summary>
|
||||
/// The Shrink Hammer's one number: the size it builds at, from a quarter of the vanilla piece up
|
||||
/// to the vanilla size. Bigger than vanilla is Trol's Hammer's job. Alt + scroll with the hammer
|
||||
/// in hand writes this same entry (BuildScale), so the slider in Configuration Manager and the
|
||||
/// wheel always agree, and the size survives a restart.
|
||||
/// </summary>
|
||||
public static class ShrinkHammerConfig
|
||||
{
|
||||
public static ConfigEntry<float> ScaleFactor;
|
||||
|
||||
public static void Bind(ConfigFile config)
|
||||
{
|
||||
ScaleFactor = config.Bind("Shrink Hammer", "Scale factor", 1f,
|
||||
new ConfigDescription("The size of the pieces the Shrink Hammer builds, against the " +
|
||||
"vanilla piece: 1 is vanilla size, 0.25 a quarter. Hold Alt and " +
|
||||
"scroll in build mode to change it in steps of 0.05. Cost and " +
|
||||
"drop never change. A ship keeps its physics at any size.",
|
||||
new AcceptableValueRange<float>(0.25f, 1f)));
|
||||
}
|
||||
|
||||
/// <summary>The multiplier a new placement should use; 1 for a value typed into the .cfg
|
||||
/// file that would make a piece too small to see, hit or remove.</summary>
|
||||
public static float ActiveFactor()
|
||||
{
|
||||
if (ScaleFactor == null) return 1f;
|
||||
return ScaleFactor.Value > 0.01f ? ScaleFactor.Value : 1f;
|
||||
}
|
||||
}
|
||||
}
|
||||
77
JotunnModStub/ShrinkHammer/ShrinkHammerItem.cs
Normal file
|
|
@ -0,0 +1,77 @@
|
|||
using Jotunn.Configs;
|
||||
using Jotunn.Entities;
|
||||
using Jotunn.Managers;
|
||||
using UnityEngine;
|
||||
|
||||
namespace RacesOfValheim
|
||||
{
|
||||
/// <summary>
|
||||
/// The Shrink Hammer: the builder's hammer for small work, down to a quarter of the vanilla size.
|
||||
/// Any race can craft it. Built the same way as <see cref="TrolsHammerItem"/>: a clone of the
|
||||
/// vanilla Hammer that keeps the vanilla piece table, so every piece, including those other mods
|
||||
/// add, is in its menu at the same cost. The size lives on the placement (TrolsHammerPatches,
|
||||
/// BuildScale), never on the piece prefabs.
|
||||
/// </summary>
|
||||
public static class ShrinkHammerItem
|
||||
{
|
||||
public const string PrefabName = "ShrinkHammer";
|
||||
public const string DisplayName = "$rov_item_shrinkhammer_name";
|
||||
|
||||
private const string SourcePrefab = "Hammer";
|
||||
private const string Label = "ShrinkHammer";
|
||||
|
||||
public static void Register()
|
||||
{
|
||||
GameObject prefab = PrefabManager.Instance.CreateClonedPrefab(PrefabName, SourcePrefab);
|
||||
ItemDrop drop = prefab != null ? prefab.GetComponent<ItemDrop>() : null;
|
||||
if (drop == null || drop.m_itemData == null || drop.m_itemData.m_shared == null)
|
||||
{
|
||||
Jotunn.Logger.LogWarning($"[{Label}] Could not clone {SourcePrefab}; {DisplayName} not registered.");
|
||||
return;
|
||||
}
|
||||
|
||||
ItemDrop.ItemData.SharedData shared = drop.m_itemData.m_shared;
|
||||
shared.m_name = DisplayName;
|
||||
shared.m_description = "$rov_item_shrinkhammer_desc";
|
||||
Sprite icon = HammerIcon.Load("ShrinkHammer_icon.png");
|
||||
if (icon != null) shared.m_icons = new[] { icon };
|
||||
|
||||
ItemManager.Instance.AddItem(new CustomItem(prefab, fixReference: false));
|
||||
ItemManager.Instance.AddRecipe(new CustomRecipe(new RecipeConfig
|
||||
{
|
||||
Item = PrefabName,
|
||||
Amount = 1,
|
||||
CraftingStation = CraftingStations.Workbench,
|
||||
MinStationLevel = 1,
|
||||
Requirements = new[]
|
||||
{
|
||||
new RequirementConfig("FineWood", 2, 0, true),
|
||||
new RequirementConfig("Resin", 2, 0, true),
|
||||
},
|
||||
}));
|
||||
|
||||
Jotunn.Logger.LogInfo($"[{Label}] {DisplayName} registered on the vanilla hammer's piece table.");
|
||||
}
|
||||
|
||||
/// <summary>Whether an item in hand is this hammer; the display name is the fallback for an
|
||||
/// ItemData built before ObjectDB finished, as in TrolsHammerItem.</summary>
|
||||
public static bool IsShrinkHammer(ItemDrop.ItemData item)
|
||||
{
|
||||
if (item == null) return false;
|
||||
if (item.m_dropPrefab != null) return item.m_dropPrefab.name == PrefabName;
|
||||
return item.m_shared != null && item.m_shared.m_name == DisplayName;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>The two hammers' own icons, painted offline (scripts/paint_hammer_icons.py) and
|
||||
/// embedded in the DLL.</summary>
|
||||
internal static class HammerIcon
|
||||
{
|
||||
public static Sprite Load(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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -52,5 +52,7 @@
|
|||
"rov_hover_ward_race_menu_ward_progression_open": "$rov_piece_racemenuward_name\n$1 progression - $2 ($3/$4)\n[<color=yellow><b>$KEY_Use</b></color>] Open\n[<color=yellow><b>Use item</b></color>] Offer a boss relic",
|
||||
"rov_hover_ward_world": "World",
|
||||
"rov_hover_boneship_roster": "\nmelee $1/$2 of $3\narchers $4/$5 of $6\naboard $7",
|
||||
"rov_hover_boneship_bone_hand": "\nbone in hand to buy a place"
|
||||
"rov_hover_boneship_bone_hand": "\nbone in hand to buy a place",
|
||||
"rov_hover_alfar_inngangskista": "Inngangskista (input)",
|
||||
"rov_hover_alfar_eldividarkista": "Eldividarkista (fuel)"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -81,8 +81,10 @@
|
|||
"rov_item_trenta_rotseed_name": "Rot Seed",
|
||||
"rov_item_trol_giantslog_desc": "A massive tree log wielded as a weapon.",
|
||||
"rov_item_trol_giantslog_name": "Giant's Log",
|
||||
"rov_item_trolshammer_desc": "A hammer swung by something that never had to duck through a doorway. It builds everything the ordinary one builds, out of the same materials, and simply builds it bigger.",
|
||||
"rov_item_trolshammer_desc": "A hammer swung by something that never had to duck through a doorway. It builds everything the ordinary one builds, out of the same materials, and simply builds it bigger. Hold Alt and scroll to choose how much bigger.",
|
||||
"rov_item_trolshammer_name": "Trol's Hammer",
|
||||
"rov_item_shrinkhammer_name": "Shrink Hammer",
|
||||
"rov_item_shrinkhammer_desc": "A fine hammer for small work. It builds everything the ordinary one builds, out of the same materials, down to a quarter of the size. Hold Alt and scroll to choose the size.",
|
||||
"rov_item_warvulture_desc": "A vulture's head, kept. Raise it and the bird comes back under you, and it will carry you as long as you care to stay up - though it only has so much haste in it before it settles into a glide.",
|
||||
"rov_item_warvulture_name": "War Vulture",
|
||||
"rov_piece_aswid_bloodrefinery_desc": "Flesh goes in, bone goes in, and what is left of both comes out red.",
|
||||
|
|
|
|||
|
|
@ -238,5 +238,10 @@
|
|||
"rov_msg_build_limit_alfar_chest": "This core already has one of these within reach.",
|
||||
"rov_msg_build_limit_alfar_ljosgard": "This core already has its Ljosgard."
|
||||
,
|
||||
"rov_msg_alfar_nexus_no_store": "The nucleus has nothing to offer right now."
|
||||
"rov_msg_alfar_nexus_no_store": "The nucleus has nothing to offer right now.",
|
||||
"rov_msg_alfar_drone_sort_nowhere": "I have nowhere to put $1. Give me an empty chest, or one that already holds $1.",
|
||||
"rov_msg_alfar_drone_sort_keep": "I leave $1 in the $2: a station here works with it.",
|
||||
"rov_msg_alfar_drone_kiln_wood": "The $4 is idle. I only burn wood from the $3, and the $1 is in another chest.",
|
||||
"rov_msg_build_scale": "Size $1",
|
||||
"rov_hint_build_scale": "Alt: Size"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -52,5 +52,7 @@
|
|||
"rov_hover_ward_race_menu_ward_progression_open": "$rov_piece_racemenuward_name\nProgressione $1 - $2 ($3/$4)\n[<color=yellow><b>$KEY_Use</b></color>] Apri\n[<color=yellow><b>Usa oggetto</b></color>] Offri una reliquia di boss",
|
||||
"rov_hover_ward_world": "del mondo",
|
||||
"rov_hover_boneship_roster": "\nmischia $1/$2 di $3\narcieri $4/$5 di $6\na bordo $7",
|
||||
"rov_hover_boneship_bone_hand": "\nosso in mano per comprare un posto"
|
||||
"rov_hover_boneship_bone_hand": "\nosso in mano per comprare un posto",
|
||||
"rov_hover_alfar_inngangskista": "Inngangskista (ingresso)",
|
||||
"rov_hover_alfar_eldividarkista": "Eldividarkista (combustibile)"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -81,8 +81,10 @@
|
|||
"rov_item_trenta_rotseed_name": "Seme marcio",
|
||||
"rov_item_trol_giantslog_desc": "Un enorme tronco d'albero brandito come arma.",
|
||||
"rov_item_trol_giantslog_name": "Tronco del gigante",
|
||||
"rov_item_trolshammer_desc": "Un martello brandito da qualcosa che non ha mai dovuto chinarsi sotto una porta. Costruisce tutto ciò che costruisce quello normale, con gli stessi materiali, e lo fa semplicemente più grande.",
|
||||
"rov_item_trolshammer_desc": "Un martello brandito da qualcosa che non ha mai dovuto chinarsi sotto una porta. Costruisce tutto ciò che costruisce quello normale, con gli stessi materiali, e lo fa semplicemente più grande. Tieni premuto Alt e usa la rotellina per scegliere quanto.",
|
||||
"rov_item_trolshammer_name": "Martello del Trol",
|
||||
"rov_item_shrinkhammer_name": "Martello Riduttore",
|
||||
"rov_item_shrinkhammer_desc": "Un martello fine per i lavori piccoli. Costruisce tutto ciò che costruisce quello normale, con gli stessi materiali, fino a un quarto della grandezza. Tieni premuto Alt e usa la rotellina per sceglierla.",
|
||||
"rov_item_warvulture_desc": "La testa di un avvoltoio, conservata. Sollevala e l'uccello torna sotto di te, e ti porterà finché vorrai restare in aria, anche se ha solo un po' di slancio prima di mettersi a planare.",
|
||||
"rov_item_warvulture_name": "Avvoltoio da guerra",
|
||||
"rov_piece_aswid_bloodrefinery_desc": "Entra carne, entra osso, e quel che resta di entrambi esce rosso.",
|
||||
|
|
|
|||
|
|
@ -238,5 +238,10 @@
|
|||
"rov_msg_build_limit_alfar_chest": "Questo nucleo ne ha gia' una nel suo raggio.",
|
||||
"rov_msg_build_limit_alfar_ljosgard": "Questo nucleo ha gia' il suo Ljosgard."
|
||||
,
|
||||
"rov_msg_alfar_nexus_no_store": "Il nucleo non ha niente da offrire adesso."
|
||||
"rov_msg_alfar_nexus_no_store": "Il nucleo non ha niente da offrire adesso.",
|
||||
"rov_msg_alfar_drone_sort_nowhere": "Non so dove mettere $1. Dammi una cassa vuota, o una che contenga già $1.",
|
||||
"rov_msg_alfar_drone_sort_keep": "Lascio $1 nella $2: una stazione qui lo usa.",
|
||||
"rov_msg_alfar_drone_kiln_wood": "$4 è fermo. Brucio solo la legna della $3, e $1 è in un'altra cassa.",
|
||||
"rov_msg_build_scale": "Grandezza $1",
|
||||
"rov_hint_build_scale": "Alt: Grandezza"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -52,5 +52,7 @@
|
|||
"rov_hover_ward_race_menu_ward_progression_open": "$rov_piece_racemenuward_name\n$1 прогресс — $2 ($3/$4)\n[<color=yellow><b>$KEY_Use</b></color>] Открыть\n[<color=yellow><b>Использовать предмет</b></color>] Пожертвовать реликвию босса",
|
||||
"rov_hover_ward_world": "Общий",
|
||||
"rov_hover_boneship_roster": "\nближний бой $1/$2 из $3\nлучники $4/$5 из $6\nна борту $7",
|
||||
"rov_hover_boneship_bone_hand": "\nкость в руке — купить место"
|
||||
"rov_hover_boneship_bone_hand": "\nкость в руке — купить место",
|
||||
"rov_hover_alfar_inngangskista": "Инганг-киста (вход)",
|
||||
"rov_hover_alfar_eldividarkista": "Эльдивидар-киста (топливо)"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -81,8 +81,10 @@
|
|||
"rov_item_trenta_rotseed_name": "Семя гнили",
|
||||
"rov_item_trol_giantslog_desc": "Исполинский ствол векового дерева, используемый как сокрушительное оружие.",
|
||||
"rov_item_trol_giantslog_name": "Бревно великана",
|
||||
"rov_item_trolshammer_desc": "Молот, которым размахивает тот, кому никогда не приходилось пригибаться в дверях. Возводит те же постройки, что и обычный молот, из тех же материалов, но с истинным тролльим размахом.",
|
||||
"rov_item_trolshammer_desc": "Молот, которым размахивает тот, кому никогда не приходилось пригибаться в дверях. Возводит те же постройки, что и обычный молот, из тех же материалов, но с истинным тролльим размахом. Зажмите Alt и крутите колесо мыши, чтобы выбрать, насколько.",
|
||||
"rov_item_trolshammer_name": "Молот тролля",
|
||||
"rov_item_shrinkhammer_name": "Молот-уменьшитель",
|
||||
"rov_item_shrinkhammer_desc": "Тонкий молот для мелкой работы. Возводит те же постройки, что и обычный молот, из тех же материалов, вплоть до четверти размера. Зажмите Alt и крутите колесо мыши, чтобы выбрать размер.",
|
||||
"rov_item_warvulture_desc": "Высушенная голова стервятника. Поднимите ее — и птица опустится вам под ноги, неся вас вперед, пока вам не надоест (хотя силы для рывка у нее быстро сменяются плавным парением).",
|
||||
"rov_item_warvulture_name": "Боевой стервятник",
|
||||
"rov_piece_aswid_bloodrefinery_desc": "Загрузите плоть, бросьте кости — и то, что от них останется, выйдет алым соком.",
|
||||
|
|
|
|||
|
|
@ -238,5 +238,10 @@
|
|||
"rov_msg_build_limit_alfar_chest": "У этого ядра уже есть такой сундук в радиусе.",
|
||||
"rov_msg_build_limit_alfar_ljosgard": "У этого ядра уже есть свой Льосгард."
|
||||
,
|
||||
"rov_msg_alfar_nexus_no_store": "У ядра сейчас нечего предложить."
|
||||
"rov_msg_alfar_nexus_no_store": "У ядра сейчас нечего предложить.",
|
||||
"rov_msg_alfar_drone_sort_nowhere": "Мне некуда положить $1. Дай мне пустой сундук или тот, где уже лежит $1.",
|
||||
"rov_msg_alfar_drone_sort_keep": "Оставляю $1 в «$2»: с этим работает станция здесь.",
|
||||
"rov_msg_alfar_drone_kiln_wood": "«$4» простаивает. Я жгу только дрова из «$3», а $1 лежит в другом сундуке.",
|
||||
"rov_msg_build_scale": "Размер $1",
|
||||
"rov_hint_build_scale": "Alt: размер"
|
||||
}
|
||||
|
|
|
|||
248
JotunnModStub/Trol/TrolSounds.cs
Normal file
|
|
@ -0,0 +1,248 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using HarmonyLib;
|
||||
using Jotunn.Entities;
|
||||
using Jotunn.Managers;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Networking;
|
||||
|
||||
namespace RacesOfValheim
|
||||
{
|
||||
/// <summary>
|
||||
/// Two rare Trol voice lines: one when a Trol dies, one when a Trol places a piece with Trol's
|
||||
/// Hammer. Each has a 1% chance by default.
|
||||
///
|
||||
/// The chance is Dota's pseudo-random distribution, not a plain roll: each try starts at a tiny
|
||||
/// chance C that grows by C after every miss and falls back to C after a hit. It averages the
|
||||
/// same chance, but long droughts and back-to-back repeats almost never happen, which suits a
|
||||
/// joke heard rarely. The miss counters live in memory and start over with the game.
|
||||
///
|
||||
/// The roll happens on the Trol's own client, which then sends the sound and the spot to every
|
||||
/// client; each one plays it there if its player is within reach.
|
||||
///
|
||||
/// A secret on purpose: no setting, and no word of it in the README, changelog or wiki. The
|
||||
/// chance and the volume are constants here for that reason.
|
||||
///
|
||||
/// The clips ship inside the DLL (Audio/*.ogg, embedded by the csproj), so no sound file sits in
|
||||
/// the plugins folder for a curious player to find. Unity can only decode Ogg from a file, so at
|
||||
/// startup each one is written to the game's temp cache under a random name, loaded, and deleted.
|
||||
/// </summary>
|
||||
public static class TrolSounds
|
||||
{
|
||||
public const string Death = "trolsdeath";
|
||||
public const string Building = "trolsbuilding";
|
||||
|
||||
private const string RpcName = "RoV_TrolSound";
|
||||
private const float Range = 20f; // metres: heard nearby, not across the base
|
||||
private const float Volume = 0.6f;
|
||||
public const float DeathChance = 1f; // percent
|
||||
public const float BuildingChance = 1f; // percent
|
||||
private const string MixerSource = "sfx_build_hammer_wood";
|
||||
|
||||
private static readonly string[] Clips = { Death, Building };
|
||||
private static readonly Dictionary<string, AudioClip> s_clips = new Dictionary<string, AudioClip>();
|
||||
private static readonly Dictionary<string, int> s_misses = new Dictionary<string, int>();
|
||||
|
||||
// --- loading ---
|
||||
|
||||
/// <summary>Loads both clips out of the DLL, by way of a file that lives only while it loads.</summary>
|
||||
public static IEnumerator Load()
|
||||
{
|
||||
foreach (string name in Clips)
|
||||
{
|
||||
byte[] bytes;
|
||||
using (Stream stream = typeof(TrolSounds).Assembly.GetManifestResourceStream(name + ".ogg"))
|
||||
{
|
||||
if (stream == null)
|
||||
{
|
||||
Jotunn.Logger.LogWarning($"[TrolSounds] No embedded clip '{name}'.");
|
||||
continue;
|
||||
}
|
||||
bytes = new byte[stream.Length];
|
||||
int read = 0;
|
||||
while (read < bytes.Length) read += stream.Read(bytes, read, bytes.Length - read);
|
||||
}
|
||||
|
||||
string path = Path.Combine(Application.temporaryCachePath, System.Guid.NewGuid().ToString("N"));
|
||||
File.WriteAllBytes(path, bytes);
|
||||
using (UnityWebRequest request = UnityWebRequestMultimedia.GetAudioClip("file:///" + path.Replace('\\', '/'), AudioType.OGGVORBIS))
|
||||
{
|
||||
yield return request.SendWebRequest();
|
||||
if (request.result == UnityWebRequest.Result.Success)
|
||||
{
|
||||
AudioClip clip = DownloadHandlerAudioClip.GetContent(request);
|
||||
clip.name = name;
|
||||
s_clips[name] = clip;
|
||||
}
|
||||
else
|
||||
{
|
||||
Jotunn.Logger.LogWarning($"[TrolSounds] Could not load '{name}': {request.error}");
|
||||
}
|
||||
}
|
||||
try { File.Delete(path); } catch (IOException) { }
|
||||
}
|
||||
}
|
||||
|
||||
// --- the roll ---
|
||||
|
||||
/// <summary>One try at a sound for the local Trol: plays it for everyone nearby on a hit.</summary>
|
||||
public static void Try(string sound, float percent, Vector3 position)
|
||||
{
|
||||
if (!Roll(sound, percent / 100f)) return;
|
||||
Broadcast(sound, position);
|
||||
}
|
||||
|
||||
private static bool Roll(string sound, float chance)
|
||||
{
|
||||
if (chance <= 0f) return false;
|
||||
if (chance >= 1f) return true;
|
||||
|
||||
s_misses.TryGetValue(sound, out int misses);
|
||||
if (Random.value < PrdConstant(chance) * (misses + 1))
|
||||
{
|
||||
s_misses[sound] = 0;
|
||||
return true;
|
||||
}
|
||||
s_misses[sound] = misses + 1;
|
||||
return false;
|
||||
}
|
||||
|
||||
private static float s_constantFor = -1f, s_constant;
|
||||
|
||||
/// <summary>
|
||||
/// The step C whose growing chance (C, 2C, 3C... until a hit) averages the chance asked for.
|
||||
/// No formula gives C; it is found by halving, once per chance value (0.000156 for 1%).
|
||||
/// </summary>
|
||||
private static float PrdConstant(float chance)
|
||||
{
|
||||
if (Mathf.Approximately(chance, s_constantFor)) return s_constant;
|
||||
|
||||
double low = 0, high = chance;
|
||||
for (int i = 0; i < 50; i++)
|
||||
{
|
||||
double c = (low + high) / 2;
|
||||
if (AverageChance(c) > chance) high = c; else low = c;
|
||||
}
|
||||
s_constantFor = chance;
|
||||
s_constant = (float)((low + high) / 2);
|
||||
return s_constant;
|
||||
}
|
||||
|
||||
/// <summary>The average chance a step of c gives: one over the expected tries to a hit.</summary>
|
||||
private static double AverageChance(double c)
|
||||
{
|
||||
double expected = 0, missedSoFar = 1;
|
||||
for (int n = 1; missedSoFar > 1e-12; n++)
|
||||
{
|
||||
double hit = System.Math.Min(1, c * n);
|
||||
expected += n * missedSoFar * hit;
|
||||
missedSoFar *= 1 - hit;
|
||||
}
|
||||
return 1 / expected;
|
||||
}
|
||||
|
||||
// --- playing ---
|
||||
|
||||
public static void Broadcast(string sound, Vector3 position)
|
||||
{
|
||||
if (ZRoutedRpc.instance != null)
|
||||
ZRoutedRpc.instance.InvokeRoutedRPC(ZRoutedRpc.Everybody, RpcName, sound, position);
|
||||
else
|
||||
Play(sound, position);
|
||||
}
|
||||
|
||||
public static void Register()
|
||||
{
|
||||
ZRoutedRpc.instance?.Register<string, Vector3>(RpcName, (sender, sound, position) => Play(sound, position));
|
||||
}
|
||||
|
||||
/// <summary>Plays a clip at a spot, if the local player is within reach of it. Through the
|
||||
/// game's sound-effects mixer, so Valheim's own SFX slider turns it down too.</summary>
|
||||
public static void Play(string sound, Vector3 position)
|
||||
{
|
||||
if (!s_clips.TryGetValue(sound, out AudioClip clip) || clip == null) return;
|
||||
Player player = Player.m_localPlayer;
|
||||
if (player != null && Vector3.Distance(player.transform.position, position) > Range) return;
|
||||
|
||||
GameObject go = new GameObject("RoV_" + sound);
|
||||
go.transform.position = position;
|
||||
AudioSource source = go.AddComponent<AudioSource>();
|
||||
source.clip = clip;
|
||||
source.volume = Volume;
|
||||
source.spatialBlend = 1f;
|
||||
source.rolloffMode = AudioRolloffMode.Linear;
|
||||
source.minDistance = 4f;
|
||||
source.maxDistance = Range;
|
||||
source.outputAudioMixerGroup = MixerGroup();
|
||||
source.Play();
|
||||
Object.Destroy(go, clip.length + 0.5f);
|
||||
}
|
||||
|
||||
private static UnityEngine.Audio.AudioMixerGroup s_mixer;
|
||||
|
||||
private static UnityEngine.Audio.AudioMixerGroup MixerGroup()
|
||||
{
|
||||
if (s_mixer != null) return s_mixer;
|
||||
GameObject sfx = PrefabManager.Cache.GetPrefab<GameObject>(MixerSource);
|
||||
AudioSource vanilla = sfx != null ? sfx.GetComponentInChildren<AudioSource>(true) : null;
|
||||
s_mixer = vanilla != null ? vanilla.outputAudioMixerGroup : null;
|
||||
return s_mixer;
|
||||
}
|
||||
|
||||
public static bool IsTrol(Player player) => FactionHostilityPatch.GetPlayerRace(player) == "Trol";
|
||||
}
|
||||
|
||||
[HarmonyPatch(typeof(Game), "Start")]
|
||||
public static class TrolSoundsRpcPatch
|
||||
{
|
||||
private static void Postfix() => TrolSounds.Register();
|
||||
}
|
||||
|
||||
[HarmonyPatch(typeof(Player), "OnDeath")]
|
||||
public static class TrolSoundsDeathPatch
|
||||
{
|
||||
private static void Prefix(Player __instance)
|
||||
{
|
||||
if (__instance != Player.m_localPlayer || !TrolSounds.IsTrol(__instance)) return;
|
||||
TrolSounds.Try(TrolSounds.Death, TrolSounds.DeathChance, __instance.transform.position);
|
||||
}
|
||||
}
|
||||
|
||||
[HarmonyPatch(typeof(Player), "PlacePiece")]
|
||||
public static class TrolSoundsBuildingPatch
|
||||
{
|
||||
private static void Postfix(Player __instance)
|
||||
{
|
||||
if (__instance != Player.m_localPlayer || !TrolsHammerItem.IsTrolsHammer(__instance.RightItem)) return;
|
||||
if (!TrolSounds.IsTrol(__instance)) return;
|
||||
TrolSounds.Try(TrolSounds.Building, TrolSounds.BuildingChance, __instance.transform.position);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// rovsnd1 / rovsnd2: play one of the two sounds now, for everyone nearby, to try it out. The
|
||||
/// names and the help say nothing about what they play: the console's help lists every command.
|
||||
/// </summary>
|
||||
public class TrolSoundCommand : ConsoleCommand
|
||||
{
|
||||
private readonly string m_name;
|
||||
private readonly string m_sound;
|
||||
|
||||
public TrolSoundCommand(string name, string sound)
|
||||
{
|
||||
m_name = name;
|
||||
m_sound = sound;
|
||||
}
|
||||
|
||||
public override string Name => m_name;
|
||||
public override string Help => "[DEBUG] Sound test.";
|
||||
|
||||
public override void Run(string[] args)
|
||||
{
|
||||
Player player = Player.m_localPlayer;
|
||||
if (player == null) { Console.instance.Print("No local player."); return; }
|
||||
TrolSounds.Broadcast(m_sound, player.transform.position);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -28,9 +28,11 @@ namespace RacesOfValheim
|
|||
"Switching this off leaves every piece already built at the size " +
|
||||
"it was built at; only new placements are affected."));
|
||||
|
||||
// Smaller than vanilla is the Shrink Hammer's job, so this one starts at 1.
|
||||
ScaleFactor = config.Bind(section, "Scale factor", 1.2f,
|
||||
new ConfigDescription("How much bigger than the vanilla piece. 1.2 is the +20% the " +
|
||||
"hammer exists for. Cost and drop never change - this is size " +
|
||||
"hammer exists for. Hold Alt and scroll in build mode to change " +
|
||||
"it in steps of 0.05. Cost and drop never change - this is size " +
|
||||
"only.", new AcceptableValueRange<float>(1f, 3f)));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -52,6 +52,9 @@ namespace RacesOfValheim
|
|||
ItemDrop.ItemData.SharedData shared = drop.m_itemData.m_shared;
|
||||
shared.m_name = DisplayName;
|
||||
shared.m_description = "$rov_item_trolshammer_desc";
|
||||
// A blue-steel head and a troll's trophy, so it cannot pass for the vanilla hammer.
|
||||
Sprite icon = HammerIcon.Load("TrolsHammer_icon.png");
|
||||
if (icon != null) shared.m_icons = new[] { icon };
|
||||
|
||||
if (shared.m_buildPieces == null)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -110,9 +110,7 @@ namespace RacesOfValheim
|
|||
|
||||
if (ghost != m_tracked) Adopt(ghost);
|
||||
|
||||
float desired = TrolsHammerItem.IsTrolsHammer(player.RightItem)
|
||||
? TrolsHammerConfig.ActiveFactor()
|
||||
: 1f;
|
||||
float desired = BuildScale.For(player.RightItem);
|
||||
|
||||
if (Mathf.Approximately(desired, m_applied)) return;
|
||||
|
||||
|
|
@ -158,9 +156,8 @@ namespace RacesOfValheim
|
|||
private static void Prefix(Player __instance)
|
||||
{
|
||||
if (__instance == null || __instance != Player.m_localPlayer) return;
|
||||
if (!TrolsHammerItem.IsTrolsHammer(__instance.RightItem)) return;
|
||||
|
||||
float factor = TrolsHammerConfig.ActiveFactor();
|
||||
// Trol's Hammer or the Shrink Hammer; any other tool builds at 1 and leaves here.
|
||||
float factor = BuildScale.For(__instance.RightItem);
|
||||
if (Mathf.Approximately(factor, 1f)) return;
|
||||
|
||||
TrolsHammerScaling.Placing = true;
|
||||
|
|
|
|||