RacesOfValheim/JotunnModStub/BoneShip/BoneShipArcher.cs
2026-10-06 11:36:18 +02:00

54 lines
2.4 KiB
C#

using UnityEngine;
using Jotunn.Managers;
namespace RacesOfValheim
{
/// <summary>
/// The archer a bone ship carries: the Bound Sentry, with the parts of it that make no sense on a deck
/// taken away and the ones that make it a ship's archer put in.
///
/// A PREFAB OF ITS OWN, not the sentry with a component added when it is spawned. A component added in
/// play is not saved: after a reload the archer would come back with no mount, and stand on nothing. This
/// one is built with ShipMount and ShipBust already on it, so a reloaded archer finds its ship again by the
/// id in its own ZDO (see ShipMount) and the roster, which counts archers by that id, never has to rebuild
/// one that was already there.
///
/// Taken away from the sentry:
/// - RaisedThrall. The orders (follow, wait, go home) are for troops; an archer on a mast of the ship
/// has no business following anyone, and E on it would send it after the player;
/// - CharacterDrop. The sentry gives back what it cost when it falls. This one is invulnerable while the
/// ship stands, and when the ship goes down it goes too - which must not pay out a soul stone and ten
/// bone fragments for every archer on every ship that sinks.
/// What stays is the bow, the AI and the tamed flag the spawner sets.
/// </summary>
public static class BoneShipArcher
{
public const string Name = "BoneShipArcher";
public static void Register()
{
// The sentry is registered by the bone pile, earlier in the same window.
GameObject prefab = PrefabManager.Instance.CreateClonedPrefab(Name, SkeletonSentry.SentryName);
if (prefab == null)
{
Jotunn.Logger.LogWarning($"[BoneShip] Could not clone '{SkeletonSentry.SentryName}'; the ships have no archers.");
return;
}
foreach (RaisedThrall thrall in prefab.GetComponentsInChildren<RaisedThrall>(true))
{
if (thrall != null) Object.DestroyImmediate(thrall);
}
foreach (CharacterDrop drop in prefab.GetComponentsInChildren<CharacterDrop>(true))
{
if (drop != null) Object.DestroyImmediate(drop);
}
prefab.AddComponent<ShipMount>();
prefab.AddComponent<ShipBust>();
PrefabManager.Instance.AddPrefab(prefab);
}
}
}