Initial commit
This commit is contained in:
commit
c4a24c9fdf
142 changed files with 15491 additions and 0 deletions
28
JotunnModStub/Trol/TMPDebug.cs
Normal file
28
JotunnModStub/Trol/TMPDebug.cs
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
using HarmonyLib;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace RacesOfValheim
|
||||
{
|
||||
[HarmonyPatch]
|
||||
public static class TMPDebug
|
||||
{
|
||||
[HarmonyPatch(typeof(Hud), "Awake")]
|
||||
[HarmonyPostfix]
|
||||
public static void Awake_Postfix(Hud __instance)
|
||||
{
|
||||
Transform food2 = __instance.transform.Find("hudroot/healthpanel/food2");
|
||||
if (food2 != null)
|
||||
{
|
||||
Transform time = food2.Find("time");
|
||||
if (time != null)
|
||||
{
|
||||
Component[] comps = time.GetComponents<Component>();
|
||||
foreach(var c in comps) {
|
||||
Jotunn.Logger.LogInfo("Time component: " + c.GetType().Name);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
11
JotunnModStub/Trol/TrolClearFoodPatch.cs
Normal file
11
JotunnModStub/Trol/TrolClearFoodPatch.cs
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
using HarmonyLib;
|
||||
namespace RacesOfValheim {
|
||||
[HarmonyPatch(typeof(Player), "ClearFood")]
|
||||
public static class Trol_ClearFood_Patch {
|
||||
public static void Postfix(Player __instance) {
|
||||
if (__instance == Player.m_localPlayer && TrolRace.IsTrol()) {
|
||||
TrolFoodManager.ClearFood(__instance);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
60
JotunnModStub/Trol/TrolDamagePatches.cs
Normal file
60
JotunnModStub/Trol/TrolDamagePatches.cs
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
using HarmonyLib;
|
||||
using UnityEngine;
|
||||
|
||||
namespace RacesOfValheim
|
||||
{
|
||||
[HarmonyPatch(typeof(Character), "ApplyDamage")]
|
||||
public static class Trol_Character_ApplyDamage_Patch
|
||||
{
|
||||
public static void Prefix(Character __instance, ref HitData hit)
|
||||
{
|
||||
if (__instance == Player.m_localPlayer && TrolRace.IsTrol())
|
||||
{
|
||||
// Trols are weak to fire (take 50% more damage)
|
||||
if (hit.m_damage.m_fire > 0f)
|
||||
{
|
||||
hit.m_damage.m_fire *= 1.5f;
|
||||
}
|
||||
}
|
||||
|
||||
if (hit.GetAttacker() == Player.m_localPlayer && TrolRace.IsTrol())
|
||||
{
|
||||
if (BossProgressionManager.GetCurrentProgressionState() >= 4) // Bonemass
|
||||
{
|
||||
if (hit.m_skill == Skills.SkillType.Clubs || hit.m_skill == Skills.SkillType.Unarmed)
|
||||
{
|
||||
hit.m_damage.m_blunt += 10f;
|
||||
}
|
||||
else if (hit.m_skill == Skills.SkillType.Axes)
|
||||
{
|
||||
hit.m_damage.m_slash += 10f;
|
||||
}
|
||||
}
|
||||
|
||||
if (BossProgressionManager.GetCurrentProgressionState() >= 6) // Yagluth
|
||||
{
|
||||
if (hit.m_skill == Skills.SkillType.Clubs || hit.m_skill == Skills.SkillType.Unarmed)
|
||||
{
|
||||
hit.m_damage.m_blunt += 5f;
|
||||
}
|
||||
else if (hit.m_skill == Skills.SkillType.Axes)
|
||||
{
|
||||
hit.m_damage.m_slash += 5f;
|
||||
}
|
||||
}
|
||||
|
||||
if (Player.m_localPlayer.GetSEMan().HaveStatusEffect("SE_TrolTrueForm".GetStableHashCode()))
|
||||
{
|
||||
if (hit.m_skill == Skills.SkillType.Clubs || hit.m_skill == Skills.SkillType.Unarmed)
|
||||
{
|
||||
hit.m_damage.m_blunt += 40f;
|
||||
}
|
||||
else if (hit.m_skill == Skills.SkillType.Axes)
|
||||
{
|
||||
hit.m_damage.m_slash += 40f;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
133
JotunnModStub/Trol/TrolExtraFoodUI.cs
Normal file
133
JotunnModStub/Trol/TrolExtraFoodUI.cs
Normal file
|
|
@ -0,0 +1,133 @@
|
|||
using HarmonyLib;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace RacesOfValheim
|
||||
{
|
||||
[HarmonyPatch]
|
||||
public static class TrolExtraFoodUI
|
||||
{
|
||||
private static GameObject TrolFoodUIBase;
|
||||
private static Image TrolFoodIcon;
|
||||
private static GameObject TrolFoodTimeObj;
|
||||
|
||||
private static GameObject TrolFoodUIBase5;
|
||||
private static Image TrolFoodIcon5;
|
||||
private static GameObject TrolFoodTimeObj5;
|
||||
|
||||
[HarmonyPatch(typeof(Hud), "Awake")]
|
||||
[HarmonyPostfix]
|
||||
public static void Awake_Postfix(Hud __instance)
|
||||
{
|
||||
Transform healthPanel = __instance.transform.Find("hudroot/healthpanel");
|
||||
if (healthPanel == null) return;
|
||||
|
||||
Transform food1 = healthPanel.Find("food1");
|
||||
Transform food2 = healthPanel.Find("food2");
|
||||
|
||||
if (food1 == null || food2 == null) return;
|
||||
|
||||
// Clone food2
|
||||
GameObject food3 = UnityEngine.Object.Instantiate(food2.gameObject, healthPanel);
|
||||
food3.name = "TrolExtraFoodSlot";
|
||||
|
||||
// Calculate vertical offset (distance between slot 1 and 2)
|
||||
float offset = food2.localPosition.y - food1.localPosition.y;
|
||||
food3.transform.localPosition = food2.localPosition + new Vector3(0, offset, 0);
|
||||
|
||||
TrolFoodUIBase = food3;
|
||||
TrolFoodIcon = food3.transform.Find("foodicon2")?.GetComponent<Image>();
|
||||
if (TrolFoodIcon == null) TrolFoodIcon = food3.transform.Find("icon")?.GetComponent<Image>(); // Fallback
|
||||
TrolFoodTimeObj = food3.transform.Find("time")?.gameObject;
|
||||
TrolFoodUIBase.SetActive(false);
|
||||
|
||||
// Clone food3 for 5th slot
|
||||
GameObject food4 = UnityEngine.Object.Instantiate(food3.gameObject, healthPanel);
|
||||
food4.name = "TrolExtraFoodSlot5";
|
||||
food4.transform.localPosition = food3.transform.localPosition + new Vector3(0, offset, 0);
|
||||
|
||||
TrolFoodUIBase5 = food4;
|
||||
TrolFoodIcon5 = food4.transform.Find("foodicon2")?.GetComponent<Image>();
|
||||
if (TrolFoodIcon5 == null) TrolFoodIcon5 = food4.transform.Find("icon")?.GetComponent<Image>();
|
||||
TrolFoodTimeObj5 = food4.transform.Find("time")?.gameObject;
|
||||
TrolFoodUIBase5.SetActive(false);
|
||||
}
|
||||
|
||||
[HarmonyPatch(typeof(Hud), "UpdateFood")]
|
||||
[HarmonyPostfix]
|
||||
public static void UpdateFood_Postfix(Hud __instance)
|
||||
{
|
||||
if (TrolFoodUIBase == null) return;
|
||||
|
||||
if (Player.m_localPlayer == null || !TrolRace.IsTrol())
|
||||
{
|
||||
TrolFoodUIBase.SetActive(false);
|
||||
if (TrolFoodUIBase5 != null) TrolFoodUIBase5.SetActive(false);
|
||||
return;
|
||||
}
|
||||
|
||||
TrolFoodUIBase.SetActive(true);
|
||||
|
||||
bool show5th = BossProgressionManager.GetCurrentProgressionState() >= 6;
|
||||
if (TrolFoodUIBase5 != null) TrolFoodUIBase5.SetActive(show5th);
|
||||
|
||||
UpdateSlotUI(Player.m_localPlayer, TrolFoodManager.ExtraFoods, TrolFoodIcon, TrolFoodTimeObj);
|
||||
|
||||
if (show5th)
|
||||
{
|
||||
UpdateSlotUI(Player.m_localPlayer, TrolFoodManager.ExtraFoods5, TrolFoodIcon5, TrolFoodTimeObj5);
|
||||
}
|
||||
}
|
||||
|
||||
private static void UpdateSlotUI(Player player, System.Collections.Generic.Dictionary<Player, Player.Food> dict, Image icon, GameObject timeObj)
|
||||
{
|
||||
if (dict.TryGetValue(player, out Player.Food extraFood) && extraFood != null)
|
||||
{
|
||||
if (icon != null)
|
||||
{
|
||||
icon.sprite = extraFood.m_item.GetIcon();
|
||||
icon.gameObject.SetActive(true);
|
||||
|
||||
bool canEat = extraFood.m_time >= (extraFood.m_item.m_shared.m_foodBurnTime * 0.5f);
|
||||
if (canEat) icon.color = new Color(1f, 1f, 1f, Mathf.Sin(Time.time * 10f) * 0.5f + 0.5f);
|
||||
else icon.color = Color.white;
|
||||
}
|
||||
|
||||
if (timeObj != null)
|
||||
{
|
||||
timeObj.SetActive(true);
|
||||
float remaining = extraFood.m_item.m_shared.m_foodBurnTime - extraFood.m_time;
|
||||
if (remaining < 0) remaining = 0;
|
||||
|
||||
string timeStr = remaining < 60f ? Mathf.CeilToInt(remaining).ToString() + "s" : Mathf.CeilToInt(remaining / 60f).ToString() + "m";
|
||||
bool canEat = extraFood.m_time >= (extraFood.m_item.m_shared.m_foodBurnTime * 0.5f);
|
||||
Color timeCol = canEat ? new Color(1f, 0.5f, 0.5f, Mathf.Sin(Time.time * 10f) * 0.5f + 0.5f) : Color.white;
|
||||
UpdateTextComponent(timeObj, timeStr, timeCol);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (icon != null) icon.gameObject.SetActive(false);
|
||||
if (timeObj != null) timeObj.SetActive(false);
|
||||
}
|
||||
}
|
||||
|
||||
private static void UpdateTextComponent(GameObject obj, string text, Color color)
|
||||
{
|
||||
var unityText = obj.GetComponent<UnityEngine.UI.Text>();
|
||||
if (unityText != null)
|
||||
{
|
||||
unityText.text = text;
|
||||
unityText.color = color;
|
||||
}
|
||||
var tmpText = obj.GetComponent("TMPro.TMP_Text");
|
||||
if (tmpText != null)
|
||||
{
|
||||
var textProp = tmpText.GetType().GetProperty("text");
|
||||
if (textProp != null) textProp.SetValue(tmpText, text, null);
|
||||
var colorProp = tmpText.GetType().GetProperty("color");
|
||||
if (colorProp != null) colorProp.SetValue(tmpText, color, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
101
JotunnModStub/Trol/TrolFarmingPatches.cs
Normal file
101
JotunnModStub/Trol/TrolFarmingPatches.cs
Normal file
|
|
@ -0,0 +1,101 @@
|
|||
using HarmonyLib;
|
||||
using UnityEngine;
|
||||
|
||||
namespace RacesOfValheim
|
||||
{
|
||||
public static class TrolFarmingHelper
|
||||
{
|
||||
public static void ApplyTrolUnarmedToolBuff(HitData hit, bool isTree)
|
||||
{
|
||||
if (hit == null) return;
|
||||
|
||||
Character attacker = hit.GetAttacker();
|
||||
if (attacker != null && attacker == Player.m_localPlayer && TrolRace.IsTrol())
|
||||
{
|
||||
ItemDrop.ItemData rightItem = HarmonyLib.Traverse.Create(Player.m_localPlayer).Field<ItemDrop.ItemData>("m_rightItem").Value;
|
||||
bool isHoldingLog = rightItem != null && rightItem.m_dropPrefab != null && rightItem.m_dropPrefab.name.StartsWith("TrolWeapon_");
|
||||
|
||||
if (isHoldingLog && isTree)
|
||||
{
|
||||
hit.m_toolTier = 10;
|
||||
hit.m_damage.m_chop = 9999f;
|
||||
return;
|
||||
}
|
||||
|
||||
if (hit.m_skill == Skills.SkillType.Unarmed)
|
||||
{
|
||||
int state = BossProgressionManager.GetCurrentProgressionState();
|
||||
|
||||
if (state >= 8) hit.m_toolTier = 5; // Fader (Fire Metal)
|
||||
else if (state >= 6) hit.m_toolTier = 4; // Yagluth (Black Metal)
|
||||
else if (state >= 5) hit.m_toolTier = 3; // Moder (Silver)
|
||||
else if (state >= 4) hit.m_toolTier = 2; // Bonemass (Iron)
|
||||
else if (state >= 3) hit.m_toolTier = 1; // Elder (Bronze)
|
||||
else if (state >= 2) hit.m_toolTier = 1; // Eikthyr (Flint/Antler)
|
||||
|
||||
float damageBonus = state * 3f;
|
||||
|
||||
// Convert blunt damage to chop or pickaxe damage, plus progression bonus
|
||||
if (isTree)
|
||||
{
|
||||
hit.m_damage.m_chop = hit.m_damage.m_blunt + damageBonus;
|
||||
Player.m_localPlayer.RaiseSkill(Skills.SkillType.WoodCutting, 1f);
|
||||
}
|
||||
else
|
||||
{
|
||||
hit.m_damage.m_pickaxe = hit.m_damage.m_blunt + damageBonus;
|
||||
Player.m_localPlayer.RaiseSkill(Skills.SkillType.Pickaxes, 1f);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[HarmonyPatch(typeof(TreeBase), "RPC_Damage")]
|
||||
public static class Trol_TreeBase_RPC_Damage_Patch
|
||||
{
|
||||
public static void Prefix(HitData hit)
|
||||
{
|
||||
TrolFarmingHelper.ApplyTrolUnarmedToolBuff(hit, true);
|
||||
}
|
||||
}
|
||||
|
||||
[HarmonyPatch(typeof(TreeLog), "RPC_Damage")]
|
||||
public static class Trol_TreeLog_RPC_Damage_Patch
|
||||
{
|
||||
public static void Prefix(HitData hit)
|
||||
{
|
||||
TrolFarmingHelper.ApplyTrolUnarmedToolBuff(hit, true);
|
||||
}
|
||||
}
|
||||
|
||||
[HarmonyPatch(typeof(Destructible), "RPC_Damage")]
|
||||
public static class Trol_Destructible_RPC_Damage_Patch
|
||||
{
|
||||
public static void Prefix(HitData hit, Destructible __instance)
|
||||
{
|
||||
// Some destructibles are trees (stumps), some are rocks.
|
||||
// We can check the destructible type.
|
||||
bool isTree = __instance.m_destructibleType == DestructibleType.Tree;
|
||||
TrolFarmingHelper.ApplyTrolUnarmedToolBuff(hit, isTree);
|
||||
}
|
||||
}
|
||||
|
||||
[HarmonyPatch(typeof(MineRock), "RPC_Hit")]
|
||||
public static class Trol_MineRock_RPC_Hit_Patch
|
||||
{
|
||||
public static void Prefix(HitData hit)
|
||||
{
|
||||
TrolFarmingHelper.ApplyTrolUnarmedToolBuff(hit, false);
|
||||
}
|
||||
}
|
||||
|
||||
[HarmonyPatch(typeof(MineRock5), "DamageArea")]
|
||||
public static class Trol_MineRock5_DamageArea_Patch
|
||||
{
|
||||
public static void Prefix(HitData hit)
|
||||
{
|
||||
TrolFarmingHelper.ApplyTrolUnarmedToolBuff(hit, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
74
JotunnModStub/Trol/TrolFoodDebug.cs
Normal file
74
JotunnModStub/Trol/TrolFoodDebug.cs
Normal file
|
|
@ -0,0 +1,74 @@
|
|||
using HarmonyLib;
|
||||
using UnityEngine;
|
||||
|
||||
namespace RacesOfValheim
|
||||
{
|
||||
[HarmonyPatch]
|
||||
public static class TrolFoodDebug
|
||||
{
|
||||
[HarmonyPatch(typeof(Player), "Update")]
|
||||
[HarmonyPostfix]
|
||||
public static void Update_Postfix(Player __instance)
|
||||
{
|
||||
if (__instance != Player.m_localPlayer) return;
|
||||
|
||||
if (Input.GetKeyDown(KeyCode.F8))
|
||||
{
|
||||
Jotunn.Logger.LogInfo("=== F8 TROL FOOD DEBUG ===");
|
||||
Jotunn.Logger.LogInfo($"IsTrol: {TrolRace.IsTrol()}");
|
||||
|
||||
var foods = Traverse.Create(__instance).Field("m_foods").GetValue<System.Collections.Generic.List<Player.Food>>();
|
||||
Jotunn.Logger.LogInfo($"Native m_foods Count: {foods?.Count ?? 0}");
|
||||
if (foods != null)
|
||||
{
|
||||
for (int i = 0; i < foods.Count; i++)
|
||||
{
|
||||
var f = foods[i];
|
||||
Jotunn.Logger.LogInfo($" [{i}] {f.m_item?.m_shared?.m_name} | Time: {f.m_time} / {f.m_item?.m_shared?.m_foodBurnTime}");
|
||||
}
|
||||
}
|
||||
|
||||
if (TrolFoodManager.ExtraFoods.TryGetValue(__instance, out Player.Food extraFood))
|
||||
{
|
||||
Jotunn.Logger.LogInfo($"ExtraFoods Dictionary has entry:");
|
||||
Jotunn.Logger.LogInfo($" Name: {extraFood?.m_item?.m_shared?.m_name}");
|
||||
Jotunn.Logger.LogInfo($" Time: {extraFood?.m_time} / {extraFood?.m_item?.m_shared?.m_foodBurnTime}");
|
||||
}
|
||||
else
|
||||
{
|
||||
Jotunn.Logger.LogInfo($"ExtraFoods Dictionary is EMPTY for this player.");
|
||||
}
|
||||
|
||||
if (__instance.m_customData.TryGetValue("TrolFood_Prefab", out string prefab))
|
||||
{
|
||||
Jotunn.Logger.LogInfo($"m_customData TrolFood_Prefab: {prefab}");
|
||||
}
|
||||
if (__instance.m_customData.TryGetValue("TrolFood_Time", out string time))
|
||||
{
|
||||
Jotunn.Logger.LogInfo($"m_customData TrolFood_Time: {time}");
|
||||
}
|
||||
Jotunn.Logger.LogInfo("==========================");
|
||||
}
|
||||
}
|
||||
|
||||
[HarmonyPatch(typeof(Humanoid), "ConsumeItem")]
|
||||
[HarmonyPrefix]
|
||||
public static void ConsumeItem_Prefix(Humanoid __instance, Inventory inventory, ItemDrop.ItemData item)
|
||||
{
|
||||
if (__instance == Player.m_localPlayer && item != null && item.m_shared.m_name == "$item_bukeperry")
|
||||
{
|
||||
Jotunn.Logger.LogInfo("=== BUKEPERRY CONSUMED ===");
|
||||
Jotunn.Logger.LogInfo($"IsTrol: {TrolRace.IsTrol()}");
|
||||
if (TrolFoodManager.ExtraFoods.ContainsKey((Player)__instance))
|
||||
{
|
||||
Jotunn.Logger.LogInfo("ExtraFoods HAS entry. Will it clear?");
|
||||
}
|
||||
else
|
||||
{
|
||||
Jotunn.Logger.LogInfo("ExtraFoods DOES NOT HAVE entry before clear.");
|
||||
}
|
||||
Jotunn.Logger.LogInfo("==========================");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
67
JotunnModStub/Trol/TrolFoodDebugUI.cs
Normal file
67
JotunnModStub/Trol/TrolFoodDebugUI.cs
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
using HarmonyLib;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace RacesOfValheim
|
||||
{
|
||||
[HarmonyPatch]
|
||||
public static class TrolFoodDebugUI
|
||||
{
|
||||
[HarmonyPatch(typeof(Player), "Update")]
|
||||
[HarmonyPostfix]
|
||||
public static void Update_Postfix(Player __instance)
|
||||
{
|
||||
if (__instance != Player.m_localPlayer) return;
|
||||
|
||||
if (Input.GetKeyDown(KeyCode.F8))
|
||||
{
|
||||
Jotunn.Logger.LogInfo("=== F8 TROL FOOD UI DEBUG ===");
|
||||
|
||||
Transform healthPanel = Hud.instance?.transform.Find("hudroot/healthpanel");
|
||||
if (healthPanel != null)
|
||||
{
|
||||
Transform food3 = healthPanel.Find("TrolExtraFoodSlot");
|
||||
if (food3 != null)
|
||||
{
|
||||
Transform timeT = food3.Find("time");
|
||||
Jotunn.Logger.LogInfo($"Found TrolExtraFoodSlot! time transform found: {timeT != null}");
|
||||
if (timeT != null)
|
||||
{
|
||||
Component[] comps = timeT.GetComponents<Component>();
|
||||
Jotunn.Logger.LogInfo("Components on 'time' object:");
|
||||
foreach(var c in comps) {
|
||||
Jotunn.Logger.LogInfo(" - " + c.GetType().FullName);
|
||||
}
|
||||
|
||||
Text timeText = timeT.GetComponent<Text>();
|
||||
Jotunn.Logger.LogInfo($"UnityEngine.UI.Text component: {timeText != null}");
|
||||
if (timeText != null) Jotunn.Logger.LogInfo($"Text value: '{timeText.text}'");
|
||||
|
||||
var tmpComp = timeT.GetComponent("TMPro.TMP_Text");
|
||||
Jotunn.Logger.LogInfo($"TMPro.TMP_Text component: {tmpComp != null}");
|
||||
if (tmpComp != null) {
|
||||
var prop = tmpComp.GetType().GetProperty("text");
|
||||
if (prop != null) {
|
||||
Jotunn.Logger.LogInfo($"TMP value: '{prop.GetValue(tmpComp, null)}'");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Jotunn.Logger.LogInfo("TrolExtraFoodSlot NOT FOUND! (Did Awake_Postfix run?)");
|
||||
}
|
||||
}
|
||||
|
||||
if (TrolFoodManager.ExtraFoods.TryGetValue(__instance, out Player.Food extraFood) && extraFood != null)
|
||||
{
|
||||
Jotunn.Logger.LogInfo($"ExtraFoods Dictionary:");
|
||||
Jotunn.Logger.LogInfo($" Name: {extraFood.m_item?.m_shared?.m_name}");
|
||||
Jotunn.Logger.LogInfo($" Time: {extraFood.m_time} / {extraFood.m_item?.m_shared?.m_foodBurnTime}");
|
||||
}
|
||||
|
||||
Jotunn.Logger.LogInfo("=============================");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
140
JotunnModStub/Trol/TrolFoodManager.cs
Normal file
140
JotunnModStub/Trol/TrolFoodManager.cs
Normal file
|
|
@ -0,0 +1,140 @@
|
|||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace RacesOfValheim
|
||||
{
|
||||
public static class TrolFoodManager
|
||||
{
|
||||
// Runtime dictionary holding the 4th food slot per player
|
||||
public static Dictionary<Player, Player.Food> ExtraFoods = new Dictionary<Player, Player.Food>();
|
||||
public static Dictionary<Player, Player.Food> ExtraFoods5 = new Dictionary<Player, Player.Food>();
|
||||
|
||||
// Called when player spawns to load the 4th and 5th food from custom data
|
||||
public static void LoadFood(Player player)
|
||||
{
|
||||
if (player == null) return;
|
||||
|
||||
// If they are no longer a Trol, clear it out
|
||||
if (!TrolRace.IsTrol())
|
||||
{
|
||||
ClearFood(player);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!player.m_customData.ContainsKey("TrolFood_Prefab")) return;
|
||||
|
||||
string prefabName = player.m_customData["TrolFood_Prefab"];
|
||||
GameObject prefab = ObjectDB.instance.GetItemPrefab(prefabName);
|
||||
if (prefab == null) return;
|
||||
|
||||
ItemDrop itemDrop = prefab.GetComponent<ItemDrop>();
|
||||
if (itemDrop == null) return;
|
||||
|
||||
// Build food object
|
||||
Player.Food food = new Player.Food();
|
||||
food.m_item = itemDrop.m_itemData.Clone(); // Clone to be safe
|
||||
|
||||
// Try parse remaining time
|
||||
if (player.m_customData.TryGetValue("TrolFood_Time", out string timeStr) && float.TryParse(timeStr, System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture, out float time))
|
||||
{
|
||||
food.m_time = time;
|
||||
}
|
||||
|
||||
food.m_health = itemDrop.m_itemData.m_shared.m_food;
|
||||
food.m_stamina = itemDrop.m_itemData.m_shared.m_foodStamina;
|
||||
food.m_eitr = itemDrop.m_itemData.m_shared.m_foodEitr;
|
||||
|
||||
ExtraFoods[player] = food;
|
||||
|
||||
if (player.m_customData.ContainsKey("TrolFood5_Prefab"))
|
||||
{
|
||||
string prefabName5 = player.m_customData["TrolFood5_Prefab"];
|
||||
GameObject prefab5 = ObjectDB.instance.GetItemPrefab(prefabName5);
|
||||
if (prefab5 != null)
|
||||
{
|
||||
ItemDrop itemDrop5 = prefab5.GetComponent<ItemDrop>();
|
||||
if (itemDrop5 != null)
|
||||
{
|
||||
Player.Food food5 = new Player.Food();
|
||||
food5.m_item = itemDrop5.m_itemData.Clone();
|
||||
if (player.m_customData.TryGetValue("TrolFood5_Time", out string timeStr5) && float.TryParse(timeStr5, System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture, out float time5))
|
||||
{
|
||||
food5.m_time = time5;
|
||||
}
|
||||
food5.m_health = itemDrop5.m_itemData.m_shared.m_food;
|
||||
food5.m_stamina = itemDrop5.m_itemData.m_shared.m_foodStamina;
|
||||
food5.m_eitr = itemDrop5.m_itemData.m_shared.m_foodEitr;
|
||||
ExtraFoods5[player] = food5;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Called to save the current runtime 4th food to custom data for persistence
|
||||
public static void SaveFood(Player player)
|
||||
{
|
||||
if (player == null) return;
|
||||
|
||||
if (ExtraFoods.TryGetValue(player, out Player.Food food) && food != null && food.m_item != null)
|
||||
{
|
||||
player.m_customData["TrolFood_Prefab"] = food.m_item.m_dropPrefab.name;
|
||||
player.m_customData["TrolFood_Time"] = food.m_time.ToString(System.Globalization.CultureInfo.InvariantCulture);
|
||||
}
|
||||
else
|
||||
{
|
||||
player.m_customData.Remove("TrolFood_Prefab");
|
||||
player.m_customData.Remove("TrolFood_Time");
|
||||
}
|
||||
|
||||
if (ExtraFoods5.TryGetValue(player, out Player.Food food5) && food5 != null && food5.m_item != null)
|
||||
{
|
||||
player.m_customData["TrolFood5_Prefab"] = food5.m_item.m_dropPrefab.name;
|
||||
player.m_customData["TrolFood5_Time"] = food5.m_time.ToString(System.Globalization.CultureInfo.InvariantCulture);
|
||||
}
|
||||
else
|
||||
{
|
||||
player.m_customData.Remove("TrolFood5_Prefab");
|
||||
player.m_customData.Remove("TrolFood5_Time");
|
||||
}
|
||||
}
|
||||
|
||||
public static void SetExtraFood(Player player, ItemDrop.ItemData item)
|
||||
{
|
||||
Player.Food food = new Player.Food();
|
||||
food.m_item = item.Clone();
|
||||
food.m_item.m_stack = 1; // Only eat 1
|
||||
food.m_time = 0f;
|
||||
food.m_health = item.m_shared.m_food;
|
||||
food.m_stamina = item.m_shared.m_foodStamina;
|
||||
food.m_eitr = item.m_shared.m_foodEitr;
|
||||
|
||||
ExtraFoods[player] = food;
|
||||
SaveFood(player);
|
||||
}
|
||||
|
||||
public static void SetExtraFood5(Player player, ItemDrop.ItemData item)
|
||||
{
|
||||
Player.Food food = new Player.Food();
|
||||
food.m_item = item.Clone();
|
||||
food.m_item.m_stack = 1;
|
||||
food.m_time = 0f;
|
||||
food.m_health = item.m_shared.m_food;
|
||||
food.m_stamina = item.m_shared.m_foodStamina;
|
||||
food.m_eitr = item.m_shared.m_foodEitr;
|
||||
|
||||
ExtraFoods5[player] = food;
|
||||
SaveFood(player);
|
||||
}
|
||||
|
||||
public static void ClearFood(Player player)
|
||||
{
|
||||
if (player == null) return;
|
||||
ExtraFoods.Remove(player);
|
||||
ExtraFoods5.Remove(player);
|
||||
player.m_customData.Remove("TrolFood_Prefab");
|
||||
player.m_customData.Remove("TrolFood_Time");
|
||||
player.m_customData.Remove("TrolFood5_Prefab");
|
||||
player.m_customData.Remove("TrolFood5_Time");
|
||||
}
|
||||
}
|
||||
}
|
||||
255
JotunnModStub/Trol/TrolFoodPatches.cs
Normal file
255
JotunnModStub/Trol/TrolFoodPatches.cs
Normal file
|
|
@ -0,0 +1,255 @@
|
|||
using HarmonyLib;
|
||||
using UnityEngine;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace RacesOfValheim
|
||||
{
|
||||
[HarmonyPatch(typeof(Player), "OnSpawned")]
|
||||
public static class Trol_PlayerOnSpawned_Patch
|
||||
{
|
||||
public static void Postfix(Player __instance)
|
||||
{
|
||||
if (__instance == Player.m_localPlayer)
|
||||
{
|
||||
TrolFoodManager.LoadFood(__instance);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[HarmonyPatch(typeof(Player), "CanConsumeItem")]
|
||||
public static class Trol_PlayerCanConsumeItem_Patch
|
||||
{
|
||||
public static bool CanTrolEat(Player player, ItemDrop.ItemData item)
|
||||
{
|
||||
var foods = Traverse.Create(player).Field("m_foods").GetValue<System.Collections.Generic.List<Player.Food>>();
|
||||
if (foods != null)
|
||||
{
|
||||
foreach (Player.Food f in foods)
|
||||
{
|
||||
if (f.m_item.m_shared.m_name == item.m_shared.m_name)
|
||||
{
|
||||
return f.CanEatAgain();
|
||||
}
|
||||
}
|
||||
if (foods.Count < 3) return true;
|
||||
}
|
||||
|
||||
bool state5 = BossProgressionManager.GetCurrentProgressionState() >= 6;
|
||||
bool has4 = TrolFoodManager.ExtraFoods.TryGetValue(player, out Player.Food food4) && food4 != null;
|
||||
bool canEat4 = has4 && food4.m_time >= (food4.m_item.m_shared.m_foodBurnTime * 0.5f);
|
||||
|
||||
bool has5 = TrolFoodManager.ExtraFoods5.TryGetValue(player, out Player.Food food5) && food5 != null;
|
||||
bool canEat5 = has5 && food5.m_time >= (food5.m_item.m_shared.m_foodBurnTime * 0.5f);
|
||||
|
||||
if (has4 && food4.m_item.m_shared.m_name == item.m_shared.m_name) return canEat4;
|
||||
if (state5 && has5 && food5.m_item.m_shared.m_name == item.m_shared.m_name) return canEat5;
|
||||
|
||||
if (!has4 || canEat4) return true;
|
||||
if (state5 && (!has5 || canEat5)) return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static bool Prefix(Player __instance, ItemDrop.ItemData item, ref bool __result)
|
||||
{
|
||||
if (__instance == Player.m_localPlayer && TrolRace.IsTrol())
|
||||
{
|
||||
if (item != null && item.m_shared != null && item.m_shared.m_itemType == ItemDrop.ItemData.ItemType.Consumable)
|
||||
{
|
||||
__result = CanTrolEat(__instance, item);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
[HarmonyPatch(typeof(Player), "EatFood")]
|
||||
public static class Trol_PlayerEatFood_Patch
|
||||
{
|
||||
private static bool CanEatNative(Player player, ItemDrop.ItemData item)
|
||||
{
|
||||
var foods = Traverse.Create(player).Field("m_foods").GetValue<List<Player.Food>>();
|
||||
if (foods != null)
|
||||
{
|
||||
foreach (Player.Food food in foods)
|
||||
{
|
||||
if (food.m_item.m_shared.m_name == item.m_shared.m_name)
|
||||
{
|
||||
return food.CanEatAgain();
|
||||
}
|
||||
}
|
||||
if (foods.Count < 3) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static bool Prefix(Player __instance, ItemDrop.ItemData item, ref bool __result)
|
||||
{
|
||||
if (__instance != Player.m_localPlayer || !TrolRace.IsTrol()) return true;
|
||||
|
||||
// If Valheim's native system can eat it (meaning it's either going to fill one of the first 3 slots,
|
||||
// or replace an already eaten flashing food), let the native system handle it completely!
|
||||
if (CanEatNative(__instance, item))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
bool state5 = BossProgressionManager.GetCurrentProgressionState() >= 6;
|
||||
|
||||
bool has4 = TrolFoodManager.ExtraFoods.TryGetValue(__instance, out Player.Food food4) && food4 != null;
|
||||
bool canEat4 = has4 && food4.m_time >= (food4.m_item.m_shared.m_foodBurnTime * 0.5f);
|
||||
|
||||
bool has5 = TrolFoodManager.ExtraFoods5.TryGetValue(__instance, out Player.Food food5) && food5 != null;
|
||||
bool canEat5 = has5 && food5.m_time >= (food5.m_item.m_shared.m_foodBurnTime * 0.5f);
|
||||
|
||||
// 1. Is it already in native slots but NOT flashing? (If flashing, CanEatNative would have caught it)
|
||||
var foods = Traverse.Create(__instance).Field("m_foods").GetValue<System.Collections.Generic.List<Player.Food>>();
|
||||
if (foods != null)
|
||||
{
|
||||
foreach (Player.Food f in foods)
|
||||
{
|
||||
if (f.m_item.m_shared.m_name == item.m_shared.m_name)
|
||||
{
|
||||
__instance.Message(MessageHud.MessageType.Center, "$msg_eatanother");
|
||||
__result = false;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 2. Is it already in slot 4 or 5?
|
||||
if (has4 && food4.m_item.m_shared.m_name == item.m_shared.m_name)
|
||||
{
|
||||
if (canEat4) { TrolFoodManager.SetExtraFood(__instance, item); ConsumeItemEffect(__instance, item); __result = true; return false; }
|
||||
else { __instance.Message(MessageHud.MessageType.Center, "$msg_eatanother"); __result = false; return false; }
|
||||
}
|
||||
if (state5 && has5 && food5.m_item.m_shared.m_name == item.m_shared.m_name)
|
||||
{
|
||||
if (canEat5) { TrolFoodManager.SetExtraFood5(__instance, item); ConsumeItemEffect(__instance, item); __result = true; return false; }
|
||||
else { __instance.Message(MessageHud.MessageType.Center, "$msg_eatanother"); __result = false; return false; }
|
||||
}
|
||||
|
||||
// 3. Not in any slots. Try to fill an empty slot or replace a flashing one
|
||||
if (!has4 || canEat4)
|
||||
{
|
||||
TrolFoodManager.SetExtraFood(__instance, item);
|
||||
ConsumeItemEffect(__instance, item);
|
||||
__result = true;
|
||||
return false;
|
||||
}
|
||||
else if (state5 && (!has5 || canEat5))
|
||||
{
|
||||
TrolFoodManager.SetExtraFood5(__instance, item);
|
||||
ConsumeItemEffect(__instance, item);
|
||||
__result = true;
|
||||
return false;
|
||||
}
|
||||
|
||||
__instance.Message(MessageHud.MessageType.Center, "$msg_canteatanymore");
|
||||
__result = false;
|
||||
return false;
|
||||
}
|
||||
|
||||
private static void ConsumeItemEffect(Player player, ItemDrop.ItemData item)
|
||||
{
|
||||
var consumeEffects = Traverse.Create(player).Field("m_consumeItemEffects").GetValue<EffectList>();
|
||||
if (consumeEffects != null)
|
||||
{
|
||||
consumeEffects.Create(player.transform.position, Quaternion.identity, player.transform, 1f, -1);
|
||||
}
|
||||
|
||||
var zanim = Traverse.Create(player).Field("m_zanim").GetValue<ZSyncAnimation>();
|
||||
if (zanim != null)
|
||||
{
|
||||
zanim.SetTrigger("eat");
|
||||
}
|
||||
|
||||
if (item.m_shared.m_food > 0f)
|
||||
{
|
||||
player.Heal(item.m_shared.m_food, true);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
[HarmonyPatch(typeof(Player), "UpdateFood")]
|
||||
public static class Trol_PlayerUpdateFood_Patch
|
||||
{
|
||||
public static void Prefix(Player __instance, float dt, bool forceUpdate)
|
||||
{
|
||||
if (__instance != Player.m_localPlayer || !TrolRace.IsTrol()) return;
|
||||
|
||||
UpdateExtraFood(__instance, TrolFoodManager.ExtraFoods, dt, 4);
|
||||
UpdateExtraFood(__instance, TrolFoodManager.ExtraFoods5, dt, 5);
|
||||
}
|
||||
|
||||
private static void UpdateExtraFood(Player player, Dictionary<Player, Player.Food> dict, float dt, int slot)
|
||||
{
|
||||
if (dict.TryGetValue(player, out Player.Food extraFood) && extraFood != null)
|
||||
{
|
||||
extraFood.m_time += dt;
|
||||
|
||||
if (extraFood.m_item != null && extraFood.m_item.m_shared != null)
|
||||
{
|
||||
if (extraFood.m_time >= extraFood.m_item.m_shared.m_foodBurnTime)
|
||||
{
|
||||
dict.Remove(player);
|
||||
if (slot == 4)
|
||||
{
|
||||
player.m_customData.Remove("TrolFood_Prefab");
|
||||
player.m_customData.Remove("TrolFood_Time");
|
||||
}
|
||||
else
|
||||
{
|
||||
player.m_customData.Remove("TrolFood5_Prefab");
|
||||
player.m_customData.Remove("TrolFood5_Time");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
float factor = extraFood.m_time / extraFood.m_item.m_shared.m_foodBurnTime;
|
||||
extraFood.m_health = Mathf.Lerp(extraFood.m_item.m_shared.m_food, extraFood.m_item.m_shared.m_food * 0.2f, factor);
|
||||
extraFood.m_stamina = Mathf.Lerp(extraFood.m_item.m_shared.m_foodStamina, extraFood.m_item.m_shared.m_foodStamina * 0.2f, factor);
|
||||
extraFood.m_eitr = Mathf.Lerp(extraFood.m_item.m_shared.m_foodEitr, extraFood.m_item.m_shared.m_foodEitr * 0.2f, factor);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[HarmonyPatch(typeof(Player), "GetTotalFoodValue")]
|
||||
public static class Trol_PlayerGetTotalFoodValue_Patch
|
||||
{
|
||||
public static void Postfix(Player __instance, ref float hp, ref float stamina, ref float eitr)
|
||||
{
|
||||
if (__instance != Player.m_localPlayer || !TrolRace.IsTrol()) return;
|
||||
|
||||
if (TrolFoodManager.ExtraFoods.TryGetValue(__instance, out Player.Food extraFood) && extraFood != null)
|
||||
{
|
||||
hp += extraFood.m_health;
|
||||
stamina += extraFood.m_stamina;
|
||||
eitr += extraFood.m_eitr;
|
||||
}
|
||||
if (BossProgressionManager.GetCurrentProgressionState() >= 6)
|
||||
{
|
||||
if (TrolFoodManager.ExtraFoods5.TryGetValue(__instance, out Player.Food extraFood5) && extraFood5 != null)
|
||||
{
|
||||
hp += extraFood5.m_health;
|
||||
stamina += extraFood5.m_stamina;
|
||||
eitr += extraFood5.m_eitr;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[HarmonyPatch(typeof(Player), "Message")]
|
||||
public static class Trol_PlayerMessage_Patch
|
||||
{
|
||||
public static bool Prefix(Player __instance, MessageHud.MessageType type, string msg)
|
||||
{
|
||||
// We no longer block eat messages so the user knows when they are full.
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
97
JotunnModStub/Trol/TrolLogWeapon.cs
Normal file
97
JotunnModStub/Trol/TrolLogWeapon.cs
Normal file
|
|
@ -0,0 +1,97 @@
|
|||
using HarmonyLib;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using Jotunn.Managers;
|
||||
using BepInEx;
|
||||
|
||||
namespace RacesOfValheim
|
||||
{
|
||||
public static class TrolLogWeapon
|
||||
{
|
||||
public static void GrabLog(Humanoid user, TreeLog logTarget)
|
||||
{
|
||||
if (user == null || logTarget == null) return;
|
||||
if (!TrolRace.IsTrol()) return;
|
||||
if (BossProgressionManager.GetCurrentProgressionState() < 7) return;
|
||||
|
||||
var seman = user.GetSEMan();
|
||||
if (seman == null) return;
|
||||
|
||||
if (!seman.HaveStatusEffect("SE_TrolTrueForm".GetStableHashCode()))
|
||||
{
|
||||
user.Message(MessageHud.MessageType.Center, "You must be in True Form to lift this!");
|
||||
return;
|
||||
}
|
||||
|
||||
string logName = Utils.GetPrefabName(logTarget.gameObject);
|
||||
if (!logName.EndsWith("_half"))
|
||||
{
|
||||
logName += "_half";
|
||||
}
|
||||
string weaponName = "TrolWeapon_" + logName;
|
||||
|
||||
GameObject weaponPrefab = PrefabManager.Cache.GetPrefab<GameObject>(weaponName);
|
||||
if (weaponPrefab == null)
|
||||
{
|
||||
weaponName = "TrolWeapon_beech_log_half"; // Fallback
|
||||
weaponPrefab = PrefabManager.Cache.GetPrefab<GameObject>(weaponName);
|
||||
}
|
||||
|
||||
if (weaponPrefab == null)
|
||||
{
|
||||
Jotunn.Logger.LogWarning("TrolWeapon prefab not found: " + weaponName);
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if already holding a weapon
|
||||
ItemDrop.ItemData rightItem = HarmonyLib.Traverse.Create(user).Field<ItemDrop.ItemData>("m_rightItem").Value;
|
||||
if (rightItem != null && rightItem.m_dropPrefab != null && rightItem.m_dropPrefab.name.StartsWith("TrolWeapon_"))
|
||||
{
|
||||
user.Message(MessageHud.MessageType.Center, "You are already holding a log!");
|
||||
return;
|
||||
}
|
||||
|
||||
// Play pickup animation
|
||||
var zanim = HarmonyLib.Traverse.Create(user).Field("m_zanim").GetValue<ZSyncAnimation>();
|
||||
if (zanim != null)
|
||||
{
|
||||
zanim.SetTrigger("interact");
|
||||
}
|
||||
|
||||
// Unequip current items for safety
|
||||
ItemDrop.ItemData currentRight = HarmonyLib.Traverse.Create(user).Field<ItemDrop.ItemData>("m_rightItem").Value;
|
||||
if (currentRight != null) user.UnequipItem(currentRight);
|
||||
ItemDrop.ItemData currentLeft = HarmonyLib.Traverse.Create(user).Field<ItemDrop.ItemData>("m_leftItem").Value;
|
||||
if (currentLeft != null) user.UnequipItem(currentLeft);
|
||||
|
||||
// Add the real weapon to inventory in a virtual slot (99, 99) to hide it
|
||||
ItemDrop wepDrop = weaponPrefab.GetComponent<ItemDrop>();
|
||||
ItemDrop.ItemData newItem = wepDrop.m_itemData.Clone();
|
||||
newItem.m_dropPrefab = weaponPrefab;
|
||||
newItem.m_gridPos = new Vector2i(99, 99);
|
||||
newItem.m_durability = newItem.GetMaxDurability();
|
||||
|
||||
var m_inventory = HarmonyLib.Traverse.Create(user.GetInventory()).Field<List<ItemDrop.ItemData>>("m_inventory").Value;
|
||||
if (m_inventory != null)
|
||||
{
|
||||
m_inventory.Add(newItem);
|
||||
HarmonyLib.Traverse.Create(user.GetInventory()).Method("Changed").GetValue();
|
||||
}
|
||||
|
||||
// Equip it
|
||||
user.EquipItem(newItem);
|
||||
|
||||
// Destroy the log in the world
|
||||
ZNetView nview = logTarget.GetComponent<ZNetView>();
|
||||
if (nview != null && nview.IsValid())
|
||||
{
|
||||
nview.ClaimOwnership();
|
||||
nview.Destroy();
|
||||
}
|
||||
else
|
||||
{
|
||||
UnityEngine.Object.Destroy(logTarget.gameObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
172
JotunnModStub/Trol/TrolPatches.cs
Normal file
172
JotunnModStub/Trol/TrolPatches.cs
Normal file
|
|
@ -0,0 +1,172 @@
|
|||
using HarmonyLib;
|
||||
using UnityEngine;
|
||||
|
||||
namespace RacesOfValheim
|
||||
{
|
||||
[HarmonyPatch(typeof(VisEquipment), "UpdateColors")]
|
||||
public static class TrolSkinColorPatch
|
||||
{
|
||||
// Golden blonde hair
|
||||
private static readonly Color HairColor = new Color(0.9f, 0.8f, 0.4f, 1f);
|
||||
|
||||
public static void Postfix(VisEquipment __instance)
|
||||
{
|
||||
if (!__instance.m_isPlayer) return;
|
||||
Player player = __instance.GetComponent<Player>();
|
||||
if (player == null) return;
|
||||
|
||||
// ZDO first (in-game + remote players), then m_customData fallback
|
||||
// (main menu preview and first spawn frame  Player.m_localPlayer is null there)
|
||||
// DO NOT check player == Player.m_localPlayer in the fallback.
|
||||
string race = "Human";
|
||||
ZNetView nview = player.GetComponent<ZNetView>();
|
||||
if (nview != null && nview.IsValid())
|
||||
race = nview.GetZDO().GetString("RacesOfValheim_Race", "Human");
|
||||
else if (player.m_customData != null &&
|
||||
player.m_customData.TryGetValue("Race", out string savedRace))
|
||||
race = savedRace;
|
||||
|
||||
if (race != "Trol") return;
|
||||
|
||||
// Apply skin, hair, beard colors here...
|
||||
if (__instance.m_bodyModel != null && __instance.m_bodyModel.material != null)
|
||||
{
|
||||
// Peacock blue (deep greenish-blue)
|
||||
Color trolColor = new Color(0.1f, 0.6f, 0.7f, 1f);
|
||||
__instance.m_bodyModel.material.SetColor("_SkinColor", trolColor);
|
||||
}
|
||||
|
||||
// Hair
|
||||
var hairInst = Traverse.Create(__instance).Field("m_hairItemInstance").GetValue<GameObject>();
|
||||
if (hairInst != null)
|
||||
foreach (var r in hairInst.GetComponentsInChildren<Renderer>())
|
||||
if (r.material != null) r.material.SetColor("_SkinColor", HairColor);
|
||||
|
||||
// Beard
|
||||
var beardInst = Traverse.Create(__instance).Field("m_beardItemInstance").GetValue<GameObject>();
|
||||
if (beardInst != null)
|
||||
foreach (var r in beardInst.GetComponentsInChildren<Renderer>())
|
||||
if (r.material != null) r.material.SetColor("_SkinColor", HairColor);
|
||||
}
|
||||
}
|
||||
|
||||
[HarmonyPatch(typeof(VisEquipment), "UpdateVisuals")]
|
||||
public static class Trol_VisEquipment_UpdateVisuals_Patch
|
||||
{
|
||||
public static string GetPlayerRace(VisEquipment visEq)
|
||||
{
|
||||
Player player = visEq.GetComponent<Player>();
|
||||
if (player != null)
|
||||
{
|
||||
ZNetView nview = player.GetComponent<ZNetView>();
|
||||
if (nview != null && nview.IsValid())
|
||||
return nview.GetZDO().GetString("RacesOfValheim_Race", "Human");
|
||||
// No Player.m_localPlayer check  works for menu preview too
|
||||
if (player.m_customData != null &&
|
||||
player.m_customData.TryGetValue("Race", out string r))
|
||||
return r;
|
||||
}
|
||||
return "Human";
|
||||
}
|
||||
|
||||
public static void Postfix(VisEquipment __instance)
|
||||
{
|
||||
if (!__instance.m_isPlayer) return;
|
||||
string race = GetPlayerRace(__instance);
|
||||
|
||||
if (race == "Trol")
|
||||
{
|
||||
// Apply model changes here...
|
||||
}
|
||||
else
|
||||
{
|
||||
// Revert changes here if needed
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[HarmonyPatch(typeof(Player), "Update")]
|
||||
public static class Trol_PlayerUpdate_Patch
|
||||
{
|
||||
public static void Postfix(Player __instance)
|
||||
{
|
||||
if (__instance == null) return;
|
||||
|
||||
string race = "Human"; ZNetView nview = __instance.GetComponent<ZNetView>(); if (nview != null && nview.IsValid()) race = nview.GetZDO().GetString("RacesOfValheim_Race", "Human"); else if (__instance.m_customData != null && __instance.m_customData.TryGetValue("Race", out string savedRace)) race = savedRace; if (race == "Trol")
|
||||
{
|
||||
// Scale player visuals up by 20%
|
||||
GameObject visual = Traverse.Create(__instance).Field("m_visual").GetValue<GameObject>();
|
||||
// Prevent overriding scale while transforming or in True Form
|
||||
bool isTrueFormActive = __instance.GetSEMan() != null && __instance.GetSEMan().HaveStatusEffect("SE_TrolTrueForm".GetStableHashCode());
|
||||
bool isTransforming = (__instance == Player.m_localPlayer && TrolRace.Instance != null && TrolRace.Instance.isTransforming);
|
||||
|
||||
if (!isTrueFormActive && !isTransforming)
|
||||
{
|
||||
float targetScale = 1.2f;
|
||||
int state = BossProgressionManager.GetCurrentProgressionState();
|
||||
if (state >= 6) targetScale = 1.30f;
|
||||
else if (state >= 4) targetScale = 1.25f;
|
||||
|
||||
if (visual != null && visual.transform.localScale != new Vector3(targetScale, targetScale, targetScale))
|
||||
{
|
||||
visual.transform.localScale = new Vector3(targetScale, targetScale, targetScale);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Reset scale if not Trol
|
||||
GameObject visual = Traverse.Create(__instance).Field("m_visual").GetValue<GameObject>();
|
||||
int state = BossProgressionManager.GetCurrentProgressionState();
|
||||
float targetScale = 1.2f;
|
||||
if (state >= 6) targetScale = 1.30f;
|
||||
else if (state >= 4) targetScale = 1.25f;
|
||||
|
||||
if (visual != null && visual.transform.localScale == new Vector3(targetScale, targetScale, targetScale))
|
||||
{
|
||||
visual.transform.localScale = Vector3.one;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[HarmonyPatch(typeof(Player), "GetMaxCarryWeight")]
|
||||
public static class Trol_GetMaxCarryWeight_Patch
|
||||
{
|
||||
public static void Postfix(Player __instance, ref float __result)
|
||||
{
|
||||
if (__instance == null) return;
|
||||
|
||||
string race = "Human"; ZNetView nview = __instance.GetComponent<ZNetView>(); if (nview != null && nview.IsValid()) race = nview.GetZDO().GetString("RacesOfValheim_Race", "Human"); else if (__instance.m_customData != null && __instance.m_customData.TryGetValue("Race", out string savedRace)) race = savedRace; if (race == "Trol")
|
||||
{
|
||||
// Base carry weight is 300. We add 200 to make it 500.
|
||||
// If they wear Megingjord, it will become 500 + 150 = 650.
|
||||
__result += 200f;
|
||||
|
||||
int state = BossProgressionManager.GetCurrentProgressionState();
|
||||
if (state >= 4)
|
||||
{
|
||||
__result += 50f; // After Bonemass
|
||||
}
|
||||
if (state >= 6)
|
||||
{
|
||||
__result += 50f; // After Yagluth
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[HarmonyPatch(typeof(Player), "GetBodyArmor")]
|
||||
public static class Trol_GetBodyArmor_Patch
|
||||
{
|
||||
public static void Postfix(Player __instance, ref float __result)
|
||||
{
|
||||
if (__instance == Player.m_localPlayer && TrolRace.IsTrol())
|
||||
{
|
||||
// +3 Armor per progression state (boss defeated)
|
||||
int state = BossProgressionManager.GetCurrentProgressionState();
|
||||
__result += 3f * state;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
392
JotunnModStub/Trol/TrolRace.cs
Normal file
392
JotunnModStub/Trol/TrolRace.cs
Normal file
|
|
@ -0,0 +1,392 @@
|
|||
using BepInEx;
|
||||
using HarmonyLib;
|
||||
using UnityEngine;
|
||||
using System.Collections.Generic;
|
||||
using Jotunn.Managers;
|
||||
using Jotunn.Entities;
|
||||
|
||||
namespace RacesOfValheim
|
||||
{
|
||||
public class TrolRace : MonoBehaviour
|
||||
{
|
||||
private static TrolRace _instance;
|
||||
public static TrolRace Instance
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_instance == null)
|
||||
{
|
||||
GameObject go = new GameObject("TrolRace");
|
||||
_instance = go.AddComponent<TrolRace>();
|
||||
DontDestroyOnLoad(go);
|
||||
}
|
||||
return _instance;
|
||||
}
|
||||
}
|
||||
|
||||
public static bool IsTrol()
|
||||
{
|
||||
if (Player.m_localPlayer == null) return false;
|
||||
ZNetView nview = Player.m_localPlayer.GetComponent<ZNetView>();
|
||||
if (nview != null && nview.IsValid())
|
||||
return nview.GetZDO().GetString("RacesOfValheim_Race", "") == "Trol";
|
||||
return Player.m_localPlayer.m_customData.TryGetValue("Race", out string r) && r == "Trol";
|
||||
}
|
||||
|
||||
public void CreateModAssets()
|
||||
{
|
||||
Jotunn.Logger.LogInfo("Initializing Trol Race...");
|
||||
TrolStatusEffects.RegisterStatusEffects();
|
||||
|
||||
// No custom projectile needed anymore
|
||||
|
||||
string[] logNames = new string[] {
|
||||
"beech_log", "beech_log_half",
|
||||
"pine_log", "pine_log_half",
|
||||
"birch_log", "birch_log_half",
|
||||
"oak_log", "oak_log_half",
|
||||
"FirTree_log", "FirTree_log_half",
|
||||
"yggdrasil_shoot_log", "yggdrasil_shoot_log_half",
|
||||
"AshTree_log", "AshTree_log_half",
|
||||
"DeadTree_log", "DeadTree_log_half",
|
||||
"SwampTree1_log", "SwampTree1_log_half",
|
||||
"SwampTree2_log", "SwampTree2_log_half"
|
||||
};
|
||||
|
||||
foreach (string logName in logNames)
|
||||
{
|
||||
GameObject logPrefab = PrefabManager.Cache.GetPrefab<GameObject>(logName);
|
||||
if (logPrefab != null)
|
||||
{
|
||||
Jotunn.Configs.ItemConfig config = new Jotunn.Configs.ItemConfig();
|
||||
config.Name = "Giant's Log";
|
||||
config.Description = "A massive tree log wielded as a weapon.";
|
||||
|
||||
CustomItem customWep = new CustomItem("TrolWeapon_" + logName, "MaceIron", config);
|
||||
if (customWep != null && customWep.ItemPrefab != null)
|
||||
{
|
||||
Transform attach = customWep.ItemPrefab.transform.Find("attach");
|
||||
if (attach != null)
|
||||
{
|
||||
foreach (Transform child in attach)
|
||||
{
|
||||
Destroy(child.gameObject);
|
||||
}
|
||||
GameObject newVisual = new GameObject("TrolWeaponVisual");
|
||||
newVisual.transform.SetParent(attach);
|
||||
newVisual.transform.localScale = new Vector3(0.4f, 0.4f, 0.4f);
|
||||
// Valheim logs are aligned along Y. Rotate Y to point along Z (forward).
|
||||
newVisual.transform.localRotation = Quaternion.Euler(90, 0, 0);
|
||||
// Offset along the local Z axis to grab it by the end instead of the middle
|
||||
newVisual.transform.localPosition = new Vector3(0, 0, 1.5f);
|
||||
|
||||
MeshRenderer[] renderers = logPrefab.GetComponentsInChildren<MeshRenderer>(true);
|
||||
foreach (var r in renderers)
|
||||
{
|
||||
if (r.name.ToLower().Contains("lod")) continue;
|
||||
GameObject part = new GameObject(r.gameObject.name);
|
||||
part.transform.SetParent(newVisual.transform);
|
||||
part.transform.localPosition = r.transform.localPosition;
|
||||
part.transform.localRotation = r.transform.localRotation;
|
||||
part.transform.localScale = r.transform.localScale;
|
||||
var mf = part.AddComponent<MeshFilter>();
|
||||
var origMf = r.GetComponent<MeshFilter>();
|
||||
if (origMf != null) mf.sharedMesh = origMf.sharedMesh;
|
||||
var mr = part.AddComponent<MeshRenderer>();
|
||||
mr.sharedMaterials = r.sharedMaterials;
|
||||
}
|
||||
}
|
||||
|
||||
ItemDrop itemDrop = customWep.ItemPrefab.GetComponent<ItemDrop>();
|
||||
itemDrop.m_itemData.m_shared.m_maxDurability = 6f;
|
||||
itemDrop.m_itemData.m_shared.m_useDurability = true;
|
||||
itemDrop.m_itemData.m_shared.m_useDurabilityDrain = 1f;
|
||||
itemDrop.m_itemData.m_shared.m_destroyBroken = false;
|
||||
itemDrop.m_itemData.m_shared.m_weight = 0f;
|
||||
itemDrop.m_itemData.m_shared.m_equipDuration = 0.1f;
|
||||
// It uses MaceIron base, so its skill is Clubs, which automatically gets our damage buffs!
|
||||
|
||||
ItemManager.Instance.AddItem(customWep);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool isTransforming = false;
|
||||
private bool wasTrueFormActive = false;
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (!IsTrol()) return;
|
||||
|
||||
if (Input.GetKeyDown(KeyCode.G))
|
||||
{
|
||||
TryThrowRock();
|
||||
}
|
||||
|
||||
if (Input.GetKeyDown(KeyCode.H))
|
||||
{
|
||||
TryTrueForm();
|
||||
}
|
||||
|
||||
// Check log durability
|
||||
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_"))
|
||||
{
|
||||
if (rightItem.m_durability <= 0f)
|
||||
{
|
||||
string logName = rightItem.m_dropPrefab.name.Substring("TrolWeapon_".Length);
|
||||
GameObject logPrefab = PrefabManager.Cache.GetPrefab<GameObject>(logName);
|
||||
if (logPrefab != null)
|
||||
{
|
||||
DropOnDestroyed dod = logPrefab.GetComponent<DropOnDestroyed>();
|
||||
if (dod != null && dod.m_dropWhenDestroyed != null)
|
||||
{
|
||||
var drops = dod.m_dropWhenDestroyed.GetDropList();
|
||||
foreach (var drop in drops)
|
||||
{
|
||||
Vector3 offset = UnityEngine.Random.insideUnitSphere * 0.5f;
|
||||
offset.y = 0.5f;
|
||||
UnityEngine.Object.Instantiate(drop, Player.m_localPlayer.transform.position + offset, Quaternion.identity);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Message removed
|
||||
Player.m_localPlayer.UnequipItem(rightItem);
|
||||
Player.m_localPlayer.GetInventory().RemoveItem(rightItem);
|
||||
}
|
||||
}
|
||||
|
||||
// Auto-revert True Form check
|
||||
bool isTrueFormActive = Player.m_localPlayer.GetSEMan().HaveStatusEffect("SE_TrolTrueForm".GetStableHashCode());
|
||||
if (wasTrueFormActive && !isTrueFormActive && !isTransforming)
|
||||
{
|
||||
StartCoroutine(RevertTrueFormRoutine());
|
||||
}
|
||||
wasTrueFormActive = isTrueFormActive;
|
||||
}
|
||||
|
||||
private void TryTrueForm()
|
||||
{
|
||||
if (BossProgressionManager.GetCurrentProgressionState() < 5) return; // Requires Moder
|
||||
|
||||
if (Player.m_localPlayer.GetSEMan().HaveStatusEffect("SE_TrolTrueForm".GetStableHashCode()))
|
||||
{
|
||||
if (BossProgressionManager.GetCurrentProgressionState() >= 7)
|
||||
{
|
||||
GameObject hoverObj = Player.m_localPlayer.GetHoverObject();
|
||||
if (hoverObj != null)
|
||||
{
|
||||
TreeLog log = hoverObj.GetComponentInParent<TreeLog>();
|
||||
if (log != null)
|
||||
{
|
||||
TrolLogWeapon.GrabLog(Player.m_localPlayer, log);
|
||||
}
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
var cdSE = Player.m_localPlayer.GetSEMan().GetStatusEffect("SE_TrolTrueFormCooldown".GetStableHashCode());
|
||||
if (cdSE != null)
|
||||
{
|
||||
float m_time = HarmonyLib.Traverse.Create(cdSE).Field<float>("m_time").Value;
|
||||
int remaining = (int)(cdSE.m_ttl - m_time);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!isTransforming)
|
||||
{
|
||||
StartCoroutine(TransformToTrueFormRoutine());
|
||||
}
|
||||
}
|
||||
|
||||
private System.Collections.IEnumerator TransformToTrueFormRoutine()
|
||||
{
|
||||
isTransforming = true;
|
||||
Player.m_localPlayer.GetSEMan().AddStatusEffect("SE_TrolTrueForm".GetStableHashCode(), true);
|
||||
Player.m_localPlayer.GetSEMan().RemoveStatusEffect("SE_TrolThrowRockCooldown".GetStableHashCode(), true);
|
||||
|
||||
float duration = 1.5f;
|
||||
float elapsed = 0f;
|
||||
GameObject visual = HarmonyLib.Traverse.Create(Player.m_localPlayer).Field("m_visual").GetValue<GameObject>();
|
||||
if (visual != null)
|
||||
{
|
||||
Vector3 startScale = visual.transform.localScale;
|
||||
float trueFormScale = BossProgressionManager.GetCurrentProgressionState() >= 7 ? 2.5f : 2.0f;
|
||||
Vector3 targetScale = new Vector3(trueFormScale, trueFormScale, trueFormScale);
|
||||
|
||||
while (elapsed < duration)
|
||||
{
|
||||
visual.transform.localScale = Vector3.Lerp(startScale, targetScale, elapsed / duration);
|
||||
elapsed += Time.deltaTime;
|
||||
yield return null;
|
||||
}
|
||||
visual.transform.localScale = targetScale;
|
||||
}
|
||||
|
||||
isTransforming = false;
|
||||
}
|
||||
|
||||
private System.Collections.IEnumerator RevertTrueFormRoutine()
|
||||
{
|
||||
isTransforming = true;
|
||||
|
||||
float duration = 1.5f;
|
||||
float elapsed = 0f;
|
||||
GameObject visual = HarmonyLib.Traverse.Create(Player.m_localPlayer).Field("m_visual").GetValue<GameObject>();
|
||||
if (visual != null)
|
||||
{
|
||||
Vector3 startScale = visual.transform.localScale;
|
||||
float normalScale = 1.2f;
|
||||
int state = BossProgressionManager.GetCurrentProgressionState();
|
||||
if (state >= 6) normalScale = 1.30f;
|
||||
else if (state >= 4) normalScale = 1.25f;
|
||||
Vector3 targetScale = new Vector3(normalScale, normalScale, normalScale);
|
||||
|
||||
while (elapsed < duration)
|
||||
{
|
||||
visual.transform.localScale = Vector3.Lerp(startScale, targetScale, elapsed / duration);
|
||||
elapsed += Time.deltaTime;
|
||||
yield return null;
|
||||
}
|
||||
visual.transform.localScale = targetScale;
|
||||
}
|
||||
|
||||
Player.m_localPlayer.GetSEMan().AddStatusEffect("SE_TrolTrueFormCooldown".GetStableHashCode(), true);
|
||||
isTransforming = false;
|
||||
}
|
||||
|
||||
private void TryThrowRock()
|
||||
{
|
||||
if (BossProgressionManager.GetCurrentProgressionState() < 3) return; // Requires The Elder
|
||||
|
||||
var cdSE = Player.m_localPlayer.GetSEMan().GetStatusEffect("SE_TrolThrowRockCooldown".GetStableHashCode());
|
||||
if (cdSE != null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
StartCoroutine(ThrowRockRoutine());
|
||||
}
|
||||
|
||||
private System.Collections.IEnumerator ThrowRockRoutine()
|
||||
{
|
||||
bool isTrueForm = Player.m_localPlayer.GetSEMan().HaveStatusEffect("SE_TrolTrueForm".GetStableHashCode());
|
||||
float throwRockCooldown = isTrueForm ? 15f : 60f;
|
||||
|
||||
var addedSE = Player.m_localPlayer.GetSEMan().AddStatusEffect("SE_TrolThrowRockCooldown".GetStableHashCode(), true);
|
||||
if (addedSE != null)
|
||||
{
|
||||
addedSE.m_ttl = throwRockCooldown;
|
||||
}
|
||||
|
||||
var zanim = HarmonyLib.Traverse.Create(Player.m_localPlayer).Field("m_zanim").GetValue<ZSyncAnimation>();
|
||||
if (zanim != null)
|
||||
{
|
||||
zanim.SetTrigger("throw_bomb");
|
||||
}
|
||||
|
||||
string logName = "";
|
||||
ItemDrop.ItemData rightItem = HarmonyLib.Traverse.Create(Player.m_localPlayer).Field<ItemDrop.ItemData>("m_rightItem").Value;
|
||||
bool isHoldingLog = rightItem != null && rightItem.m_dropPrefab != null && rightItem.m_dropPrefab.name.StartsWith("TrolWeapon_");
|
||||
|
||||
if (isHoldingLog)
|
||||
{
|
||||
logName = rightItem.m_dropPrefab.name.Substring("TrolWeapon_".Length);
|
||||
|
||||
// Remove the weapon from inventory
|
||||
Player.m_localPlayer.UnequipItem(rightItem);
|
||||
Player.m_localPlayer.GetInventory().RemoveItem(rightItem);
|
||||
}
|
||||
|
||||
// Wait a moment for the animation to reach the throw point
|
||||
yield return new WaitForSeconds(0.4f);
|
||||
|
||||
Vector3 spawnPos = Player.m_localPlayer.GetEyePoint() + Player.m_localPlayer.GetLookDir() * 1.5f;
|
||||
|
||||
if (isHoldingLog && !string.IsNullOrEmpty(logName))
|
||||
{
|
||||
// Spawn original log asset further away so it doesn't instantly collide with the player
|
||||
Vector3 logSpawnPos = Player.m_localPlayer.GetEyePoint() + Player.m_localPlayer.GetLookDir() * 3.5f;
|
||||
GameObject originalLogPrefab = ZNetScene.instance.GetPrefab(logName);
|
||||
if (originalLogPrefab != null)
|
||||
{
|
||||
GameObject logInstance = UnityEngine.Object.Instantiate(originalLogPrefab, logSpawnPos, Quaternion.LookRotation(Player.m_localPlayer.GetLookDir()));
|
||||
|
||||
Rigidbody rb = logInstance.GetComponent<Rigidbody>();
|
||||
if (rb == null) rb = logInstance.GetComponentInChildren<Rigidbody>();
|
||||
|
||||
if (rb != null)
|
||||
{
|
||||
// 3x speed to compensate for log weight/drag
|
||||
rb.velocity = Player.m_localPlayer.GetLookDir() * 60f;
|
||||
// Add some slight rotation tumbling
|
||||
rb.angularVelocity = new Vector3(10f, 5f, 0f);
|
||||
}
|
||||
logInstance.AddComponent<LogImpactBreaker>();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Default rock throw
|
||||
GameObject projPrefab = ZNetScene.instance.GetPrefab("troll_throw_projectile");
|
||||
if (projPrefab != null)
|
||||
{
|
||||
GameObject projInstance = UnityEngine.Object.Instantiate(projPrefab, spawnPos, Quaternion.LookRotation(Player.m_localPlayer.GetLookDir()));
|
||||
|
||||
Projectile proj = projInstance.GetComponent<Projectile>();
|
||||
if (proj != null)
|
||||
{
|
||||
HitData hitData = new HitData();
|
||||
hitData.m_damage.m_blunt = 25f; // Base troll rock
|
||||
|
||||
if (BossProgressionManager.GetCurrentProgressionState() >= 4)
|
||||
{
|
||||
hitData.m_damage.m_blunt += 10f; // Bonemass bonus
|
||||
}
|
||||
if (BossProgressionManager.GetCurrentProgressionState() >= 6)
|
||||
{
|
||||
hitData.m_damage.m_blunt += 5f; // Yagluth bonus
|
||||
}
|
||||
|
||||
if (isTrueForm)
|
||||
{
|
||||
hitData.m_damage.m_blunt += 40f; // True Form bonus
|
||||
}
|
||||
|
||||
hitData.SetAttacker(Player.m_localPlayer);
|
||||
proj.Setup(Player.m_localPlayer, Player.m_localPlayer.GetLookDir() * 20f, -1f, hitData, null, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class LogImpactBreaker : MonoBehaviour
|
||||
{
|
||||
private bool broken = false;
|
||||
private float armTime;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
armTime = Time.time + 0.2f;
|
||||
}
|
||||
|
||||
private void OnCollisionEnter(Collision collision)
|
||||
{
|
||||
if (broken || Time.time < armTime) return;
|
||||
broken = true;
|
||||
|
||||
Destructible destructible = GetComponent<Destructible>();
|
||||
if (destructible != null)
|
||||
{
|
||||
HitData hitData = new HitData();
|
||||
hitData.m_damage.m_chop = 9999f;
|
||||
hitData.m_point = collision.contacts.Length > 0 ? collision.contacts[0].point : transform.position;
|
||||
destructible.Damage(hitData);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
20
JotunnModStub/Trol/TrolRegenPatches.cs
Normal file
20
JotunnModStub/Trol/TrolRegenPatches.cs
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
using HarmonyLib;
|
||||
|
||||
namespace RacesOfValheim
|
||||
{
|
||||
[HarmonyPatch(typeof(SEMan), "ModifyHealthRegen")]
|
||||
public static class Trol_SEMan_ModifyHealthRegen_Patch
|
||||
{
|
||||
public static void Postfix(SEMan __instance, ref float regenMultiplier)
|
||||
{
|
||||
if (__instance == Player.m_localPlayer?.GetSEMan() && TrolRace.IsTrol())
|
||||
{
|
||||
// After The Elder (Progression State >= 2)
|
||||
if (BossProgressionManager.GetCurrentProgressionState() >= 3)
|
||||
{
|
||||
regenMultiplier *= 1.10f; // +10% passive health regeneration
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
32
JotunnModStub/Trol/TrolSkillPatches.cs
Normal file
32
JotunnModStub/Trol/TrolSkillPatches.cs
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
using HarmonyLib;
|
||||
|
||||
namespace RacesOfValheim
|
||||
{
|
||||
[HarmonyPatch(typeof(Skills), "RaiseSkill")]
|
||||
public static class Trol_Skills_RaiseSkill_Patch
|
||||
{
|
||||
public static void Prefix(Skills __instance, Skills.SkillType skillType, ref float factor)
|
||||
{
|
||||
Player player = HarmonyLib.Traverse.Create(__instance).Field("m_player").GetValue<Player>();
|
||||
if (player != null && player == Player.m_localPlayer && TrolRace.IsTrol())
|
||||
{
|
||||
// After Eikthyr (Progression State >= 1)
|
||||
if (BossProgressionManager.GetCurrentProgressionState() >= 2)
|
||||
{
|
||||
bool isTrolSkill = (
|
||||
skillType == Skills.SkillType.Clubs ||
|
||||
skillType == Skills.SkillType.Unarmed ||
|
||||
skillType == Skills.SkillType.Axes ||
|
||||
skillType == Skills.SkillType.Pickaxes ||
|
||||
skillType == Skills.SkillType.WoodCutting
|
||||
);
|
||||
|
||||
if (isTrolSkill)
|
||||
{
|
||||
factor *= 2f;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
91
JotunnModStub/Trol/TrolStatusEffects.cs
Normal file
91
JotunnModStub/Trol/TrolStatusEffects.cs
Normal file
|
|
@ -0,0 +1,91 @@
|
|||
using Jotunn.Managers;
|
||||
using Jotunn.Entities;
|
||||
using UnityEngine;
|
||||
|
||||
namespace RacesOfValheim
|
||||
{
|
||||
public class SE_TrolThrowRockCooldown : SE_Stats
|
||||
{
|
||||
public override void Setup(Character character)
|
||||
{
|
||||
base.Setup(character);
|
||||
name = "SE_TrolThrowRockCooldown";
|
||||
m_name = "Throw Rock Cooldown";
|
||||
m_tooltip = "You must wait before throwing another rock.";
|
||||
m_ttl = 60f; // 1 minute cooldown
|
||||
|
||||
// Try to find a rock-like icon, e.g. Stone
|
||||
GameObject itemPrefab = PrefabManager.Cache.GetPrefab<GameObject>("Stone");
|
||||
if (itemPrefab != null)
|
||||
{
|
||||
ItemDrop drop = itemPrefab.GetComponent<ItemDrop>();
|
||||
if (drop != null && drop.m_itemData.m_shared.m_icons.Length > 0)
|
||||
{
|
||||
m_icon = drop.m_itemData.m_shared.m_icons[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class SE_TrolTrueForm : SE_Stats
|
||||
{
|
||||
public override void Setup(Character character)
|
||||
{
|
||||
base.Setup(character);
|
||||
name = "SE_TrolTrueForm";
|
||||
m_name = "True Form";
|
||||
m_tooltip = "You have unleashed your inner troll!";
|
||||
m_ttl = 60f; // 1 minute duration
|
||||
|
||||
GameObject itemPrefab = PrefabManager.Cache.GetPrefab<GameObject>("Stone");
|
||||
if (itemPrefab != null)
|
||||
{
|
||||
ItemDrop drop = itemPrefab.GetComponent<ItemDrop>();
|
||||
if (drop != null && drop.m_itemData.m_shared.m_icons.Length > 0)
|
||||
{
|
||||
m_icon = drop.m_itemData.m_shared.m_icons[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class SE_TrolTrueFormCooldown : SE_Stats
|
||||
{
|
||||
public override void Setup(Character character)
|
||||
{
|
||||
base.Setup(character);
|
||||
name = "SE_TrolTrueFormCooldown";
|
||||
m_name = "True Form Cooldown";
|
||||
m_tooltip = "You are exhausted from your True Form.";
|
||||
m_ttl = 600f; // 10 minutes cooldown
|
||||
|
||||
GameObject itemPrefab = PrefabManager.Cache.GetPrefab<GameObject>("Stone");
|
||||
if (itemPrefab != null)
|
||||
{
|
||||
ItemDrop drop = itemPrefab.GetComponent<ItemDrop>();
|
||||
if (drop != null && drop.m_itemData.m_shared.m_icons.Length > 0)
|
||||
{
|
||||
m_icon = drop.m_itemData.m_shared.m_icons[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class TrolStatusEffects
|
||||
{
|
||||
public static void RegisterStatusEffects()
|
||||
{
|
||||
var cdSE = ScriptableObject.CreateInstance<SE_TrolThrowRockCooldown>();
|
||||
cdSE.name = "SE_TrolThrowRockCooldown";
|
||||
ItemManager.Instance.AddStatusEffect(new CustomStatusEffect(cdSE, fixReference: false));
|
||||
|
||||
var tfSE = ScriptableObject.CreateInstance<SE_TrolTrueForm>();
|
||||
tfSE.name = "SE_TrolTrueForm";
|
||||
ItemManager.Instance.AddStatusEffect(new CustomStatusEffect(tfSE, fixReference: false));
|
||||
|
||||
var tfCdSE = ScriptableObject.CreateInstance<SE_TrolTrueFormCooldown>();
|
||||
tfCdSE.name = "SE_TrolTrueFormCooldown";
|
||||
ItemManager.Instance.AddStatusEffect(new CustomStatusEffect(tfCdSE, fixReference: false));
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue