139 lines
8.3 KiB
C#
139 lines
8.3 KiB
C#
using BepInEx.Configuration;
|
|
|
|
namespace RacesOfValheim
|
|
{
|
|
/// <summary>
|
|
/// Every tunable number behind the War Vulture, bound as BepInEx ConfigEntry so it shows up in
|
|
/// Configuration Manager - same shape as TrolConfig, which is the house model for this.
|
|
///
|
|
/// The three numbers most likely to need a pass in game are deliberately here rather than in
|
|
/// code: MountSize, MountOffsetY and MountOffsetZ. Where a bird sits under a rider is the one
|
|
/// thing the last attempt lost three rounds to (section 16.6 of the design doc: measure a
|
|
/// relation, never pick a number in metres from the armchair), and a value that can be dragged
|
|
/// in the menu while standing in the world beats another compile.
|
|
///
|
|
/// No keybind is bound here on purpose. The mount answers to LEFT CLICK on the item and to the
|
|
/// vanilla run key, so there is nothing new to learn and nothing new to rebind.
|
|
/// </summary>
|
|
public static class WarVultureConfig
|
|
{
|
|
// ─── Access ────────────────────────────────────────────────────────────
|
|
public static ConfigEntry<string> AllowedRaces;
|
|
|
|
// ─── Flight ────────────────────────────────────────────────────────────
|
|
public static ConfigEntry<float> CruiseSpeed;
|
|
public static ConfigEntry<float> SprintSpeed;
|
|
public static ConfigEntry<float> SprintSeconds;
|
|
public static ConfigEntry<float> RechargeSeconds;
|
|
public static ConfigEntry<float> LandingSpeed;
|
|
|
|
// ─── Model ─────────────────────────────────────────────────────────────
|
|
public static ConfigEntry<float> HandModelScale;
|
|
public static ConfigEntry<float> MountSize;
|
|
public static ConfigEntry<string> SeatBone;
|
|
public static ConfigEntry<float> SeatNudgeY;
|
|
public static ConfigEntry<float> SeatNudgeZ;
|
|
|
|
// ─── Interface ─────────────────────────────────────────────────────────
|
|
public static ConfigEntry<bool> ShowStaminaBar;
|
|
|
|
public static void Bind(ConfigFile config)
|
|
{
|
|
const string access = "War Vulture - Access";
|
|
AllowedRaces = config.Bind(access, "Allowed races", "Furling,Dvergar",
|
|
new ConfigDescription("Comma separated list of race ids that can call the vulture. " +
|
|
"In anyone else's hands the item is an inert trophy on a stick. " +
|
|
"Leave empty to let every race ride."));
|
|
|
|
const string flight = "War Vulture - Flight";
|
|
// 7 and 13 are not proposals: they are m_flySlowSpeed and m_flyFastSpeed read off the
|
|
// vanilla Volture at runtime (design doc 15.13). A number read from the game survives a
|
|
// Valheim patch; a number invented here does not.
|
|
CruiseSpeed = config.Bind(flight, "Cruise speed", 7f,
|
|
new ConfigDescription("Metres per second with the run key up. This one is unlimited - " +
|
|
"vultures stay up for hours."));
|
|
SprintSpeed = config.Bind(flight, "Sprint speed", 13f,
|
|
new ConfigDescription("Metres per second while the run key is held and the bird still " +
|
|
"has wind in it."));
|
|
SprintSeconds = config.Bind(flight, "Sprint seconds", 10f,
|
|
new ConfigDescription("How long full speed lasts before the bird drops back to cruise."));
|
|
RechargeSeconds = config.Bind(flight, "Recharge seconds", 10f,
|
|
new ConfigDescription("How long a spent bird takes to fill up again. It recharges in the " +
|
|
"air as soon as the run key is released - landing is not required."));
|
|
LandingSpeed = config.Bind(flight, "Landing speed", 12f,
|
|
new ConfigDescription("Metres per second of the automatic descent after the dismount " +
|
|
"click. The controls are ignored until the ground arrives."));
|
|
|
|
const string model = "War Vulture - Model";
|
|
HandModelScale = config.Bind(model, "Hand model scale", 0.6f,
|
|
new ConfigDescription("Size of the vulture trophy carried in hand, as a fraction of the " +
|
|
"real trophy. 0.6 is the 40% smaller that was asked for."));
|
|
MountSize = config.Bind(model, "Mount size", 7.75f,
|
|
new ConfigDescription("Largest dimension of the bird under the rider, in metres. 7.75 is " +
|
|
"the vanilla Volture's own mesh, wings included."));
|
|
// The rider is glued to a BONE, not to a height: the bird's back rises and falls with
|
|
// every wingbeat, and any offset in metres can only be right on one frame of that.
|
|
SeatBone = config.Bind(model, "Seat bone", "",
|
|
new ConfigDescription("Name (or part of a name) of the bone on the vulture's skeleton the " +
|
|
"rider sits on. Empty picks the last spine/chest bone automatically, " +
|
|
"which is what the bird actually flies with."));
|
|
SeatNudgeY = config.Bind(model, "Seat nudge Y", 0f,
|
|
new ConfigDescription("Fine adjustment up (+) or down (-) from the seat bone, in metres. " +
|
|
"Zero means exactly on the bone."));
|
|
SeatNudgeZ = config.Bind(model, "Seat nudge Z", 0f,
|
|
new ConfigDescription("Fine adjustment forward (+) or back (-) from the seat bone, in metres."));
|
|
|
|
const string ui = "War Vulture - Interface";
|
|
ShowStaminaBar = config.Bind(ui, "Show stamina bar", true,
|
|
new ConfigDescription("Draws the bird's own wind as a bar under the player's stamina, " +
|
|
"cloned from vanilla's mount stamina bar."));
|
|
}
|
|
|
|
/// <summary>
|
|
/// The race of a player, read m_customData first and the ZDO second.
|
|
///
|
|
/// That order is the one the summon has always used, and it is kept rather than swapped for
|
|
/// the ZDO-first order the visuals use, for a reason: this only ever asks about the LOCAL
|
|
/// player, whose m_customData is authoritative and is written before the ZDO on a race
|
|
/// change. The ZDO is the fallback for the one frame after a load where m_customData has not
|
|
/// been filled in yet - without it the crafting list would flicker the recipe away.
|
|
/// </summary>
|
|
public static string RaceOf(Player player)
|
|
{
|
|
if (player == null) return null;
|
|
|
|
if (player.m_customData != null &&
|
|
player.m_customData.TryGetValue("Race", out string custom) &&
|
|
!string.IsNullOrEmpty(custom))
|
|
{
|
|
return custom;
|
|
}
|
|
|
|
ZNetView nview = player.GetComponent<ZNetView>();
|
|
if (nview != null && nview.IsValid())
|
|
{
|
|
string race = nview.GetZDO().GetString("RacesOfValheim_Race", "");
|
|
if (!string.IsNullOrEmpty(race)) return race;
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Whether a race id may call the bird. An empty list means everyone, which is the honest
|
|
/// reading of "no restriction" and is also what makes this testable on any character.
|
|
/// </summary>
|
|
public static bool RaceAllowed(string race)
|
|
{
|
|
string list = AllowedRaces != null ? AllowedRaces.Value : null;
|
|
if (string.IsNullOrEmpty(list)) return true;
|
|
if (string.IsNullOrEmpty(race)) return false;
|
|
|
|
foreach (string entry in list.Split(','))
|
|
{
|
|
if (entry.Trim().Equals(race.Trim(), System.StringComparison.OrdinalIgnoreCase)) return true;
|
|
}
|
|
return false;
|
|
}
|
|
}
|
|
}
|