Merge branch 'fix-trol-log-grab-gamepad': Trol Grab Log on the Use key

This commit is contained in:
kanym 2026-10-29 13:22:44 +01:00
commit 3b194eaec9
5 changed files with 44 additions and 6 deletions

View file

@ -45,7 +45,7 @@
"rov_hover_trenta_ready_empty": "ready: $1 $2\n[<color=yellow><b>$KEY_Use</b></color>] Empty it",
"rov_hover_trenta_rotting_minutes_left": "rotting, $1 minutes left",
"rov_hover_trol_call_warbands": "\n[<color=yellow><b>$KEY_Use</b></color>] Call the warbands",
"rov_hover_trol_grab_log": "\n[<color=yellow><b>$1</b></color>] Grab Log",
"rov_hover_trol_grab_log": "\n[<color=yellow><b>$KEY_Use</b></color>] Grab Log",
"rov_hover_trol_warbands": "warbands $1/$2",
"rov_hover_trol_yagluth_drop_hand_buys_king": "\n(a Yagluth drop in hand buys a king's head, and two more bands)",
"rov_hover_ward_personal": "Personal",

View file

@ -45,7 +45,7 @@
"rov_hover_trenta_ready_empty": "pronto: $1 $2\n[<color=yellow><b>$KEY_Use</b></color>] Svuotala",
"rov_hover_trenta_rotting_minutes_left": "sta marcendo, mancano $1 minuti",
"rov_hover_trol_call_warbands": "\n[<color=yellow><b>$KEY_Use</b></color>] Chiama le bande da guerra",
"rov_hover_trol_grab_log": "\n[<color=yellow><b>$1</b></color>] Afferra il tronco",
"rov_hover_trol_grab_log": "\n[<color=yellow><b>$KEY_Use</b></color>] Afferra il tronco",
"rov_hover_trol_warbands": "bande da guerra $1/$2",
"rov_hover_trol_yagluth_drop_hand_buys_king": "\n(un bottino di Yagluth in mano compra la testa di un re, e altre due bande)",
"rov_hover_ward_personal": "Personale",

View file

@ -45,7 +45,7 @@
"rov_hover_trenta_ready_empty": "готово: $1 $2\n[<color=yellow><b>$KEY_Use</b></color>] Опустошить",
"rov_hover_trenta_rotting_minutes_left": "гниет, осталось $1 мин",
"rov_hover_trol_call_warbands": "\n[<color=yellow><b>$KEY_Use</b></color>] Созвать боевые дружины",
"rov_hover_trol_grab_log": "\n[<color=yellow><b>$1</b></color>] Взять бревно",
"rov_hover_trol_grab_log": "\n[<color=yellow><b>$KEY_Use</b></color>] Взять бревно",
"rov_hover_trol_warbands": "дружины $1/$2",
"rov_hover_trol_yagluth_drop_hand_buys_king": "\n(трофей Яглута в руке позволит насадить голову конунга и нанять еще две дружины)",
"rov_hover_ward_personal": "Личный",

View file

@ -87,7 +87,7 @@ namespace RacesOfValheim
TrueFormKey = config.Bind(keybinds, "True Form", new KeyboardShortcut(KeyCode.H),
new ConfigDescription("Transform into (or revert from) True Form, tier 5+."));
GrabLogKey = config.Bind(keybinds, "Grab Log", new KeyboardShortcut(KeyCode.E),
new ConfigDescription("Grabs a felled log as a weapon while looking at one, tier 7+ and already in True Form. Matches vanilla's own interact key rather than reusing the True Form key a second time."));
new ConfigDescription("Grabs a felled log as a weapon while looking at one, tier 7+ and already in True Form. The game's own Use key (gamepad included) always grabs too; this is an extra key on top of it."));
const string combat = "Trol - Passive Combat";
FireWeaknessMultiplier = config.Bind(combat, "Fire Weakness Multiplier", 1.5f,

View file

@ -8,11 +8,18 @@ namespace RacesOfValheim
{
public static class TrolLogWeapon
{
// Two readers can ask for the same press: the game's own Use (Trol_LogGrabInteract_Patch)
// and the Grab Log key, which is E by default like Use. The second one in the same press
// would only say the troll already holds a log.
private const float GrabDebounce = 0.5f;
private static float lastGrabTime = -100f;
public static void GrabLog(Humanoid user, TreeLog logTarget)
{
if (user == null || logTarget == null) return;
if (!TrolRace.IsTrol()) return;
if (BossProgressionManager.GetCurrentProgressionState() < 7) return;
if (Time.time - lastGrabTime < GrabDebounce) return;
var seman = user.GetSEMan();
if (seman == null) return;
@ -107,6 +114,8 @@ namespace RacesOfValheim
{
UnityEngine.Object.Destroy(logTarget.gameObject);
}
lastGrabTime = Time.time;
}
}
@ -136,8 +145,37 @@ namespace RacesOfValheim
ItemDrop.ItemData rightItem = HarmonyLib.Traverse.Create(Player.m_localPlayer).Field<ItemDrop.ItemData>("m_rightItem").Value;
if (rightItem != null && rightItem.m_dropPrefab != null && rightItem.m_dropPrefab.name.StartsWith("TrolWeapon_")) return;
string key = TrolConfig.GrabLogKey.Value.MainKey.ToString();
__result += ModText.Get("rov_hover_trol_grab_log", key);
// The game's Use key, which ModText resolves to the pad's own button on a gamepad. The
// Grab Log key still works, but only Use reaches every device.
__result += ModText.Get("rov_hover_trol_grab_log");
}
}
/// <summary>
/// Grab Log on the game's own Use, keyboard and gamepad alike, the way the Aswid's Dominate
/// works. Dominate is an Interactable, so vanilla's Player.Interact finds it; a log carries
/// only HoverText, which is not one, so Use on a log did nothing and the Grab Log key (read
/// off the keyboard) was the only way in. A pad had none.
///
/// Taken over only for a True Form Trol at tier 7+, who is the one shown the prompt; anyone
/// else's Use on a log goes on to vanilla, which does nothing with it.
/// </summary>
[HarmonyPatch(typeof(Player), "Interact")]
public static class Trol_LogGrabInteract_Patch
{
public static bool Prefix(Player __instance, GameObject go, bool hold)
{
if (__instance != Player.m_localPlayer || go == null || !TrolRace.IsTrol()) return true;
if (BossProgressionManager.GetCurrentProgressionState() < 7) return true;
if (!__instance.GetSEMan().HaveStatusEffect("SE_TrolTrueForm".GetStableHashCode())) return true;
if (__instance.InAttack() || __instance.InDodge()) return true;
TreeLog log = go.GetComponentInParent<TreeLog>();
if (log == null) return true;
// Holding Use repeats the call every frame: one press, one grab.
if (!hold) TrolLogWeapon.GrabLog(__instance, log);
return false;
}
}
}