Initial commit
This commit is contained in:
commit
c4a24c9fdf
142 changed files with 15491 additions and 0 deletions
110
JotunnModStub/Aswid/AswidExtraFoodUI.cs
Normal file
110
JotunnModStub/Aswid/AswidExtraFoodUI.cs
Normal file
|
|
@ -0,0 +1,110 @@
|
|||
using HarmonyLib;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace RacesOfValheim
|
||||
{
|
||||
[HarmonyPatch]
|
||||
public static class AswidExtraFoodUI
|
||||
{
|
||||
private static GameObject AswidFoodUIBase;
|
||||
private static Image AswidFoodIcon;
|
||||
private static GameObject AswidFoodTimeObj;
|
||||
|
||||
[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 = "AswidExtraFoodSlot";
|
||||
|
||||
// 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);
|
||||
|
||||
AswidFoodUIBase = food3;
|
||||
AswidFoodIcon = food3.transform.Find("foodicon2")?.GetComponent<Image>();
|
||||
if (AswidFoodIcon == null) AswidFoodIcon = food3.transform.Find("icon")?.GetComponent<Image>(); // Fallback
|
||||
AswidFoodTimeObj = food3.transform.Find("time")?.gameObject;
|
||||
AswidFoodUIBase.SetActive(false);
|
||||
}
|
||||
|
||||
[HarmonyPatch(typeof(Hud), "UpdateFood")]
|
||||
[HarmonyPostfix]
|
||||
public static void UpdateFood_Postfix(Hud __instance)
|
||||
{
|
||||
if (AswidFoodUIBase == null) return;
|
||||
|
||||
bool show4th = BossProgressionManager.GetCurrentProgressionState() >= 8;
|
||||
|
||||
if (Player.m_localPlayer == null || !AswidRace.IsAswid() || !show4th)
|
||||
{
|
||||
AswidFoodUIBase.SetActive(false);
|
||||
return;
|
||||
}
|
||||
|
||||
AswidFoodUIBase.SetActive(true);
|
||||
UpdateSlotUI(Player.m_localPlayer, AswidFoodManager.ExtraFoods, AswidFoodIcon, AswidFoodTimeObj);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
88
JotunnModStub/Aswid/AswidFoodManager.cs
Normal file
88
JotunnModStub/Aswid/AswidFoodManager.cs
Normal file
|
|
@ -0,0 +1,88 @@
|
|||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace RacesOfValheim
|
||||
{
|
||||
public static class AswidFoodManager
|
||||
{
|
||||
// Runtime dictionary holding the 4th food slot per player
|
||||
public static Dictionary<Player, Player.Food> ExtraFoods = new Dictionary<Player, Player.Food>();
|
||||
|
||||
// Called when player spawns to load the 4th food from custom data
|
||||
public static void LoadFood(Player player)
|
||||
{
|
||||
if (player == null) return;
|
||||
|
||||
// If they are no longer an Aswid, clear it out
|
||||
if (!AswidRace.IsAswid())
|
||||
{
|
||||
ClearFood(player);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!player.m_customData.ContainsKey("AswidFood_Prefab")) return;
|
||||
|
||||
string prefabName = player.m_customData["AswidFood_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("AswidFood_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;
|
||||
}
|
||||
|
||||
// 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["AswidFood_Prefab"] = food.m_item.m_dropPrefab.name;
|
||||
player.m_customData["AswidFood_Time"] = food.m_time.ToString(System.Globalization.CultureInfo.InvariantCulture);
|
||||
}
|
||||
else
|
||||
{
|
||||
player.m_customData.Remove("AswidFood_Prefab");
|
||||
player.m_customData.Remove("AswidFood_Time");
|
||||
}
|
||||
}
|
||||
|
||||
public static void ClearFood(Player player)
|
||||
{
|
||||
ExtraFoods.Remove(player);
|
||||
if (player != null)
|
||||
{
|
||||
player.m_customData.Remove("AswidFood_Prefab");
|
||||
player.m_customData.Remove("AswidFood_Time");
|
||||
}
|
||||
}
|
||||
|
||||
public static void SetExtraFood(Player player, ItemDrop.ItemData item)
|
||||
{
|
||||
Player.Food food = new Player.Food();
|
||||
food.m_item = item.Clone();
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
776
JotunnModStub/Aswid/AswidPatches.cs
Normal file
776
JotunnModStub/Aswid/AswidPatches.cs
Normal file
|
|
@ -0,0 +1,776 @@
|
|||
using HarmonyLib;
|
||||
using UnityEngine;
|
||||
using System.Linq;
|
||||
|
||||
namespace RacesOfValheim
|
||||
{
|
||||
[HarmonyPatch(typeof(VisEquipment), "UpdateColors")]
|
||||
public static class AswidSkinColorPatch
|
||||
{
|
||||
private static readonly Color SkinColor = new Color(0.96f, 0.97f, 0.98f, 1f);
|
||||
private static readonly Color HairColor = new Color(1f, 1f, 1f, 1f);
|
||||
|
||||
public static void Postfix(VisEquipment __instance)
|
||||
{
|
||||
if (!__instance.m_isPlayer) return;
|
||||
Player player = __instance.GetComponent<Player>();
|
||||
if (player == null) return;
|
||||
|
||||
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 != "Aswid") return;
|
||||
|
||||
int state = 0;
|
||||
if (nview != null && nview.IsValid())
|
||||
state = nview.GetZDO().GetInt("RacesOfValheim_AswidState", 0);
|
||||
|
||||
Color currentHairColor = state >= 8 ? new Color(0.02f, 0.02f, 0.02f, 1f) : HairColor;
|
||||
|
||||
if (__instance.m_bodyModel != null && __instance.m_bodyModel.material != null)
|
||||
__instance.m_bodyModel.material.SetColor("_SkinColor", SkinColor);
|
||||
|
||||
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", currentHairColor);
|
||||
|
||||
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", currentHairColor);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
[HarmonyPatch(typeof(SEMan), "AddStatusEffect", new System.Type[] { typeof(int), typeof(bool), typeof(int), typeof(float) })]
|
||||
public static class AswidSEManPatch
|
||||
{
|
||||
public static bool Prefix(SEMan __instance, ref int nameHash)
|
||||
{
|
||||
Character character = Traverse.Create(__instance).Field<Character>("m_character").Value;
|
||||
if (character == Player.m_localPlayer && AswidRace.IsAswid())
|
||||
{
|
||||
int state = BossProgressionManager.GetCurrentProgressionState();
|
||||
if (state >= 5 && nameHash == "Freezing".GetStableHashCode())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Cold immunity is removed as per user request to test native Cold VFX
|
||||
// if (nameHash == "Cold".GetStableHashCode())
|
||||
// {
|
||||
// return false;
|
||||
// }
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
[HarmonyPatch(typeof(Attack), "Start")]
|
||||
public static class Aswid_BloodMagicCost_Patch
|
||||
{
|
||||
private static float savedHealthCost = 0f;
|
||||
private static float savedHealthPercentage = 0f;
|
||||
|
||||
public static void Prefix(Attack __instance, Humanoid character, ref bool __state)
|
||||
{
|
||||
var weapon = Traverse.Create(__instance).Field("m_weapon").GetValue<ItemDrop.ItemData>();
|
||||
if (weapon == null) weapon = Traverse.Create(__instance).Method("GetWeapon").GetValue<ItemDrop.ItemData>();
|
||||
|
||||
if (character == Player.m_localPlayer && AswidRace.IsAswid() && weapon != null && weapon.m_shared.m_skillType == Skills.SkillType.BloodMagic)
|
||||
{
|
||||
__state = true;
|
||||
savedHealthCost = weapon.m_shared.m_attack.m_attackHealth;
|
||||
savedHealthPercentage = weapon.m_shared.m_attack.m_attackHealthPercentage;
|
||||
|
||||
weapon.m_shared.m_attack.m_attackHealth = 0f;
|
||||
weapon.m_shared.m_attack.m_attackHealthPercentage = 0f;
|
||||
}
|
||||
else
|
||||
{
|
||||
__state = false;
|
||||
}
|
||||
}
|
||||
|
||||
public static void Postfix(Attack __instance, Humanoid character, bool __state)
|
||||
{
|
||||
var weapon = Traverse.Create(__instance).Field("m_weapon").GetValue<ItemDrop.ItemData>();
|
||||
if (weapon == null) weapon = Traverse.Create(__instance).Method("GetWeapon").GetValue<ItemDrop.ItemData>();
|
||||
|
||||
if (__state && weapon != null)
|
||||
{
|
||||
weapon.m_shared.m_attack.m_attackHealth = savedHealthCost;
|
||||
weapon.m_shared.m_attack.m_attackHealthPercentage = savedHealthPercentage;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class AswidPatches
|
||||
{
|
||||
public static System.Collections.Generic.Dictionary<ZDOID, float> RecentlyLifeDrained = new System.Collections.Generic.Dictionary<ZDOID, float>();
|
||||
}
|
||||
|
||||
[HarmonyPatch(typeof(Character), "Damage")]
|
||||
public static class Aswid_LifeDrainKill_Patch
|
||||
{
|
||||
public static void Postfix(Character __instance, HitData hit)
|
||||
{
|
||||
if (hit != null && hit.m_attacker == Player.m_localPlayer?.GetZDOID())
|
||||
{
|
||||
Debug.LogWarning($"[Aswid_Patch] Local player damaged {__instance.name}. IsDead: {__instance.IsDead()}");
|
||||
}
|
||||
|
||||
if (__instance.IsDead() && hit != null)
|
||||
{
|
||||
if (Player.m_localPlayer != null && hit.m_attacker == Player.m_localPlayer.GetZDOID())
|
||||
{
|
||||
ZNetView cNetView = __instance.GetComponent<ZNetView>();
|
||||
if (AswidRace.IsAswid() && cNetView != null && cNetView.IsValid())
|
||||
{
|
||||
ZDOID zdoid = __instance.GetZDOID();
|
||||
if (AswidPatches.RecentlyLifeDrained.TryGetValue(zdoid, out float timeHit))
|
||||
{
|
||||
if (Time.time - timeHit < 1.0f)
|
||||
{
|
||||
Debug.LogWarning($"[Aswid] {__instance.name} died within 1s of LifeDrain. Consuming!");
|
||||
AswidRace.TryConsumeMob(__instance, __instance.GetMaxHealth());
|
||||
AswidPatches.RecentlyLifeDrained.Remove(zdoid);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[HarmonyPatch(typeof(Character), "Awake")]
|
||||
public static class Aswid_Awake_Patch
|
||||
{
|
||||
public static void Postfix(Character __instance)
|
||||
{
|
||||
if (__instance.GetComponent<MonsterAI>() != null && !__instance.IsBoss() && __instance.m_faction != Character.Faction.Demon && __instance.GetComponent<Tameable>() == null)
|
||||
{
|
||||
if (__instance.GetComponent<AswidThrall>() == null)
|
||||
{
|
||||
__instance.gameObject.AddComponent<AswidThrall>();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[HarmonyPatch(typeof(Player), "GetBodyArmor")]
|
||||
public static class Aswid_ArmorBonus_Patch
|
||||
{
|
||||
public static void Postfix(Player __instance, ref float __result)
|
||||
{
|
||||
if (__instance == Player.m_localPlayer && AswidRace.IsAswid())
|
||||
{
|
||||
int state = BossProgressionManager.GetCurrentProgressionState();
|
||||
float multiplier = (EnvMan.instance != null && EnvMan.IsNight()) ? 2f : 1f;
|
||||
__result += 1f * state * multiplier;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[HarmonyPatch]
|
||||
public static class Aswid_DamageBonus_Patch
|
||||
{
|
||||
[HarmonyTargetMethod]
|
||||
public static System.Reflection.MethodBase TargetMethod()
|
||||
{
|
||||
return System.Linq.Enumerable.FirstOrDefault(
|
||||
HarmonyLib.AccessTools.GetDeclaredMethods(typeof(ItemDrop.ItemData)),
|
||||
m => m.Name == "GetDamage" && m.ReturnType == typeof(HitData.DamageTypes)
|
||||
);
|
||||
}
|
||||
|
||||
public static void Postfix(ItemDrop.ItemData __instance, ref HitData.DamageTypes __result)
|
||||
{
|
||||
if (Player.m_localPlayer != null && AswidRace.IsAswid() &&
|
||||
Player.m_localPlayer.GetInventory().ContainsItem(__instance))
|
||||
{
|
||||
int state = BossProgressionManager.GetCurrentProgressionState();
|
||||
if (state > 0)
|
||||
{
|
||||
float multiplier = (EnvMan.instance != null && EnvMan.IsNight()) ? 2f : 1f;
|
||||
float bonus = 2f * state * multiplier;
|
||||
|
||||
// Add flat bonus to physical damage types that the weapon already has
|
||||
if (__result.m_slash > 0) __result.m_slash += bonus;
|
||||
if (__result.m_blunt > 0) __result.m_blunt += bonus;
|
||||
if (__result.m_pierce > 0) __result.m_pierce += bonus;
|
||||
if (__result.m_chop > 0) __result.m_chop += bonus;
|
||||
if (__result.m_pickaxe > 0) __result.m_pickaxe += bonus;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[HarmonyPatch(typeof(Humanoid), "StartAttack")]
|
||||
public static class Aswid_Attack_Patch
|
||||
{
|
||||
public static bool Prefix(Humanoid __instance)
|
||||
{
|
||||
if (__instance == Player.m_localPlayer)
|
||||
{
|
||||
if (__instance.GetComponentInChildren<BatFormBehavior>() != null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (__instance.GetSEMan().HaveStatusEffect("SE_MistForm".GetStableHashCode()))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
[HarmonyPatch(typeof(Character), "SetRun")]
|
||||
public static class Aswid_Run_Patch
|
||||
{
|
||||
public static void Prefix(Character __instance, ref bool run)
|
||||
{
|
||||
if (__instance == Player.m_localPlayer)
|
||||
{
|
||||
if (Player.m_localPlayer.GetSEMan().HaveStatusEffect("SE_MistForm".GetStableHashCode()))
|
||||
{
|
||||
run = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[HarmonyPatch(typeof(Character), "Jump")]
|
||||
public static class Aswid_Jump_Patch
|
||||
{
|
||||
public static bool Prefix(Character __instance)
|
||||
{
|
||||
if (__instance == Player.m_localPlayer)
|
||||
{
|
||||
if (Player.m_localPlayer.GetSEMan().HaveStatusEffect("SE_MistForm".GetStableHashCode()))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
[HarmonyPatch(typeof(Player), "OnSpawned")]
|
||||
public static class Aswid_PlayerOnSpawned_Patch
|
||||
{
|
||||
public static void Postfix(Player __instance)
|
||||
{
|
||||
if (__instance == Player.m_localPlayer)
|
||||
{
|
||||
AswidFoodManager.LoadFood(__instance);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[HarmonyPatch(typeof(Player), "CanConsumeItem")]
|
||||
public static class Aswid_CanConsumeItem_Patch
|
||||
{
|
||||
public static void Postfix(Player __instance, ItemDrop.ItemData item, ref bool __result)
|
||||
{
|
||||
if (__instance == Player.m_localPlayer && AswidRace.IsAswid() && item != null && item.m_shared != null && item.m_shared.m_name.StartsWith("Aswid Food:"))
|
||||
{
|
||||
var foods = HarmonyLib.Traverse.Create(__instance).Field("m_foods").GetValue<System.Collections.IList>();
|
||||
if (foods != null)
|
||||
{
|
||||
if (foods.Count >= 3)
|
||||
{
|
||||
bool canUse4th = BossProgressionManager.GetCurrentProgressionState() >= 8;
|
||||
bool has4th = AswidFoodManager.ExtraFoods.TryGetValue(__instance, out Player.Food extraFood) && extraFood != null;
|
||||
|
||||
if (canUse4th && (!has4th || extraFood.m_time >= (extraFood.m_item.m_shared.m_foodBurnTime * 0.5f)))
|
||||
{
|
||||
__result = true; // Consente l'uso del 4° slot se disponibile
|
||||
}
|
||||
else
|
||||
{
|
||||
__result = false; // Nessuno spazio disponibile, cibo si disintegra
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
__result = true; // Spazio nei primi 3 slot
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[HarmonyPatch(typeof(Player), "EatFood")]
|
||||
public static class Aswid_EatFood_Patch
|
||||
{
|
||||
private static System.Collections.Generic.List<object> hiddenFoods = new System.Collections.Generic.List<object>();
|
||||
|
||||
public static bool Prefix(Player __instance, ItemDrop.ItemData item, ref bool __result)
|
||||
{
|
||||
hiddenFoods.Clear();
|
||||
if (__instance == Player.m_localPlayer && AswidRace.IsAswid() && item != null && item.m_shared != null && item.m_shared.m_name.StartsWith("Aswid Food:"))
|
||||
{
|
||||
var m_foods = HarmonyLib.Traverse.Create(__instance).Field("m_foods").GetValue<System.Collections.IList>();
|
||||
if (m_foods != null)
|
||||
{
|
||||
if (m_foods.Count >= 3)
|
||||
{
|
||||
bool canUse4th = BossProgressionManager.GetCurrentProgressionState() >= 8;
|
||||
if (canUse4th)
|
||||
{
|
||||
bool has4th = AswidFoodManager.ExtraFoods.TryGetValue(__instance, out Player.Food extraFood) && extraFood != null;
|
||||
if (!has4th || extraFood.m_time >= (extraFood.m_item.m_shared.m_foodBurnTime * 0.5f))
|
||||
{
|
||||
AswidFoodManager.SetExtraFood(__instance, item);
|
||||
|
||||
// Play consume effects
|
||||
var consumeEffects = HarmonyLib.Traverse.Create(__instance).Field("m_consumeItemEffects").GetValue<EffectList>();
|
||||
if (consumeEffects != null)
|
||||
{
|
||||
consumeEffects.Create(__instance.transform.position, Quaternion.identity, __instance.transform, 1f, -1);
|
||||
}
|
||||
var zanim = HarmonyLib.Traverse.Create(__instance).Field("m_zanim").GetValue<ZSyncAnimation>();
|
||||
if (zanim != null)
|
||||
{
|
||||
zanim.SetTrigger("eat");
|
||||
}
|
||||
if (item.m_shared.m_food > 0f)
|
||||
{
|
||||
__instance.Heal(item.m_shared.m_food, true);
|
||||
}
|
||||
|
||||
__result = true;
|
||||
return false; // Skip native EatFood
|
||||
}
|
||||
}
|
||||
|
||||
// Se pieno e senza 4° slot disponibile, fallisce e disintegra
|
||||
__result = false;
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Nascondiamo temporaneamente i duplicati nei primi 3 slot per costringere Valheim ad aggiungere un NUOVO slot
|
||||
for (int i = m_foods.Count - 1; i >= 0; i--)
|
||||
{
|
||||
var foodObj = m_foods[i];
|
||||
var foodItem = HarmonyLib.Traverse.Create(foodObj).Field("m_item").GetValue<ItemDrop.ItemData>();
|
||||
if (foodItem != null && foodItem.m_shared.m_name == item.m_shared.m_name)
|
||||
{
|
||||
hiddenFoods.Add(foodObj);
|
||||
m_foods.RemoveAt(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static void Postfix(Player __instance, ItemDrop.ItemData item, ref bool __result)
|
||||
{
|
||||
if (hiddenFoods.Count > 0)
|
||||
{
|
||||
var m_foods = HarmonyLib.Traverse.Create(__instance).Field("m_foods").GetValue<System.Collections.IList>();
|
||||
if (m_foods != null)
|
||||
{
|
||||
// Ripristiniamo i duplicati nascosti
|
||||
foreach (var hf in hiddenFoods)
|
||||
{
|
||||
m_foods.Add(hf);
|
||||
}
|
||||
}
|
||||
hiddenFoods.Clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[HarmonyPatch(typeof(Tameable), "GetHoverText")]
|
||||
public static class Aswid_TameHoverText_Patch
|
||||
{
|
||||
public static void Postfix(Tameable __instance, ref string __result)
|
||||
{
|
||||
if (Player.m_localPlayer == null || !AswidRace.IsAswid()) return;
|
||||
if (__instance.GetComponent<Character>()?.IsTamed() == true) return;
|
||||
|
||||
string prefabName = __instance.gameObject.name.ToLower();
|
||||
int state = BossProgressionManager.GetCurrentProgressionState();
|
||||
|
||||
bool canTame = false;
|
||||
if (state >= 2 && prefabName.Contains("boar")) canTame = true;
|
||||
if (state >= 5 && prefabName.Contains("wolf")) canTame = true;
|
||||
if (state >= 6 && prefabName.Contains("lox")) canTame = true;
|
||||
if (state >= 8 && prefabName.Contains("asksvin")) canTame = true;
|
||||
|
||||
if (canTame)
|
||||
{
|
||||
__result += "\n[<color=yellow><b></b></color>] Tame";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[HarmonyPatch(typeof(Tameable), "Interact")]
|
||||
public static class Aswid_TameInteract_Patch
|
||||
{
|
||||
public static bool Prefix(Tameable __instance, Humanoid user, bool hold, bool alt)
|
||||
{
|
||||
if (hold || alt) return true;
|
||||
if (user != Player.m_localPlayer || !AswidRace.IsAswid()) return true;
|
||||
if (__instance.GetComponent<Character>()?.IsTamed() == true) return true;
|
||||
|
||||
string prefabName = __instance.gameObject.name.ToLower();
|
||||
int state = BossProgressionManager.GetCurrentProgressionState();
|
||||
|
||||
bool canTame = false;
|
||||
if (state >= 2 && prefabName.Contains("boar")) canTame = true;
|
||||
if (state >= 5 && prefabName.Contains("wolf")) canTame = true;
|
||||
if (state >= 6 && prefabName.Contains("lox")) canTame = true;
|
||||
if (state >= 8 && prefabName.Contains("asksvin")) canTame = true;
|
||||
|
||||
if (canTame)
|
||||
{
|
||||
__instance.GetComponent<Character>()?.SetTamed(true);
|
||||
HarmonyLib.Traverse.Create(__instance).Method("Tame").GetValue(); // attempt to call Tame for VFX if it exists
|
||||
__instance.Command(user);
|
||||
user.Message(MessageHud.MessageType.Center, "Tamed!");
|
||||
return false; // Skip original interact
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
[HarmonyPatch(typeof(Hud), "UpdateStamina")]
|
||||
public static class Aswid_HideStamina_Patch
|
||||
{
|
||||
public static bool Prefix(Hud __instance, Player player)
|
||||
{
|
||||
if (player == Player.m_localPlayer && AswidRace.IsAswid())
|
||||
{
|
||||
if (__instance.m_staminaBar2Root != null && __instance.m_staminaBar2Root.gameObject.activeSelf)
|
||||
{
|
||||
__instance.m_staminaBar2Root.gameObject.SetActive(false);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
[HarmonyPatch(typeof(StatusEffect), "Setup")]
|
||||
public static class Aswid_ColdStatus_Patch
|
||||
{
|
||||
public static void Prefix(StatusEffect __instance, Character character)
|
||||
{
|
||||
if (character == Player.m_localPlayer && AswidRace.IsAswid() && (__instance.name.Contains("Cold") || __instance.m_name == "$se_cold_name"))
|
||||
{
|
||||
var wraithTrophy = Jotunn.Managers.PrefabManager.Cache.GetPrefab<ItemDrop>("TrophyWraith");
|
||||
if (wraithTrophy != null && wraithTrophy.m_itemData.m_shared.m_icons.Length > 0)
|
||||
{
|
||||
__instance.m_icon = wraithTrophy.m_itemData.m_shared.m_icons[0];
|
||||
}
|
||||
else
|
||||
{
|
||||
__instance.m_icon = null;
|
||||
}
|
||||
|
||||
__instance.m_name = "Night Aura";
|
||||
__instance.m_startMessage = ""; // "The darkness empowers you.";
|
||||
__instance.m_tooltip = "The cold strengthens your beastly senses.";
|
||||
|
||||
if (__instance is SE_Stats stats)
|
||||
{
|
||||
stats.m_healthRegenMultiplier = 1f;
|
||||
stats.m_staminaRegenMultiplier = 1f;
|
||||
stats.m_staminaDrainPerSec = 0f;
|
||||
stats.m_speedModifier = 0f;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
[HarmonyPatch(typeof(Player), "Update")]
|
||||
public static class Aswid_PlayerUpdate_Patch
|
||||
{
|
||||
public static void Postfix(Player __instance)
|
||||
{
|
||||
if (__instance == null) return;
|
||||
ZNetView nview = __instance.GetComponent<ZNetView>();
|
||||
if (nview != null && nview.IsValid() && nview.GetZDO().GetString("RacesOfValheim_Race", "Human") == "Aswid")
|
||||
{
|
||||
if (__instance == Player.m_localPlayer && Input.GetKeyDown(KeyCode.I))
|
||||
{
|
||||
AswidRace.DevourEnabled = !AswidRace.DevourEnabled;
|
||||
string msg = AswidRace.DevourEnabled ? "Abilità Divora: ATTIVATA" : "Abilità Divora: DISATTIVATA";
|
||||
__instance.Message(MessageHud.MessageType.Center, msg);
|
||||
}
|
||||
|
||||
int state = BossProgressionManager.GetCurrentProgressionState();
|
||||
var rules = AswidProgression.GetRules(state);
|
||||
|
||||
if (AswidRace.Instance != null && !AswidRace.Instance.IsTransformed)
|
||||
{
|
||||
if (rules != null && rules.HasSurtlingForm)
|
||||
{
|
||||
__instance.transform.localScale = new Vector3(1.1f, 1.1f, 1.1f);
|
||||
}
|
||||
else
|
||||
{
|
||||
__instance.transform.localScale = Vector3.one;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[HarmonyPatch(typeof(VisEquipment), "UpdateVisuals")]
|
||||
public static class Aswid_MultiplayerVisuals_Patch
|
||||
{
|
||||
public static void Postfix(VisEquipment __instance)
|
||||
{
|
||||
if (!__instance.m_isPlayer) return;
|
||||
Player player = __instance.GetComponent<Player>();
|
||||
if (player == null || player.IsOwner()) return; // Only process for remote players
|
||||
|
||||
ZNetView nview = player.GetComponent<ZNetView>();
|
||||
if (nview != null && nview.IsValid() && nview.GetZDO().GetString("RacesOfValheim_Race", "Human") == "Aswid")
|
||||
{
|
||||
bool isBat = nview.GetZDO().GetBool("Aswid_IsBatForm", false);
|
||||
bool isMist = nview.GetZDO().GetBool("Aswid_IsMistForm", false);
|
||||
|
||||
Transform playerVisual = player.transform.Find("Visual");
|
||||
|
||||
// Bat logic
|
||||
Transform batBody = player.transform.Find("AswidBody_Bat");
|
||||
if (isBat && batBody == null) {
|
||||
GameObject batPrefab = Jotunn.Managers.PrefabManager.Cache.GetPrefab<GameObject>("Bat");
|
||||
if (batPrefab != null) {
|
||||
GameObject visualPrefab = batPrefab.GetComponentInChildren<Animator>()?.gameObject;
|
||||
if (visualPrefab != null) {
|
||||
GameObject batInstance = UnityEngine.Object.Instantiate(visualPrefab, player.transform.position, player.transform.rotation, player.transform);
|
||||
batInstance.name = "AswidBody_Bat";
|
||||
batInstance.transform.localPosition = Vector3.zero;
|
||||
}
|
||||
}
|
||||
} else if (!isBat && batBody != null) {
|
||||
UnityEngine.Object.Destroy(batBody.gameObject);
|
||||
}
|
||||
|
||||
// Mist logic
|
||||
Transform mistBody = player.transform.Find("AswidBody_Mist");
|
||||
if (isMist && mistBody == null) {
|
||||
GameObject wraithPrefab = Jotunn.Managers.PrefabManager.Cache.GetPrefab<GameObject>("Wraith");
|
||||
if (wraithPrefab != null) {
|
||||
GameObject visualPrefab = wraithPrefab.transform.Find("Visual")?.gameObject;
|
||||
if (visualPrefab != null) {
|
||||
GameObject mistInstance = UnityEngine.Object.Instantiate(visualPrefab, player.transform.position, player.transform.rotation, player.transform);
|
||||
mistInstance.name = "AswidBody_Mist";
|
||||
mistInstance.transform.localPosition = Vector3.zero;
|
||||
mistInstance.transform.localScale = Vector3.one;
|
||||
foreach (var r in mistInstance.GetComponentsInChildren<Renderer>())
|
||||
{
|
||||
if (r.material != null && r.material.HasProperty("_Color"))
|
||||
{
|
||||
Color c = r.material.GetColor("_Color");
|
||||
c.a = 0.3f; // Make transparent
|
||||
r.material.SetColor("_Color", c);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (!isMist && mistBody != null) {
|
||||
UnityEngine.Object.Destroy(mistBody.gameObject);
|
||||
}
|
||||
|
||||
// Toggle visibility
|
||||
if (isBat || isMist) {
|
||||
if (playerVisual != null) playerVisual.gameObject.SetActive(false);
|
||||
} else {
|
||||
if (playerVisual != null) playerVisual.gameObject.SetActive(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[HarmonyPatch(typeof(Player), "Update")]
|
||||
public static class Aswid_Debug_F8_Patch
|
||||
{
|
||||
public static void Postfix(Player __instance)
|
||||
{
|
||||
if (__instance == Player.m_localPlayer && UnityEngine.Input.GetKeyDown(UnityEngine.KeyCode.F8))
|
||||
{
|
||||
Jotunn.Logger.LogInfo("[AswidDebug] F8 pressed! Finding nearest mob to consume...");
|
||||
Character nearest = null;
|
||||
float minDist = 10f;
|
||||
foreach (Character c in Character.GetAllCharacters())
|
||||
{
|
||||
if (c != __instance && c.GetHealth() > 0)
|
||||
{
|
||||
float dist = UnityEngine.Vector3.Distance(__instance.transform.position, c.transform.position);
|
||||
if (dist < minDist)
|
||||
{
|
||||
minDist = dist;
|
||||
nearest = c;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (nearest != null)
|
||||
{
|
||||
Jotunn.Logger.LogInfo($"[AswidDebug] Consuming {nearest.name} via F8!");
|
||||
AswidRace.TryConsumeMob(nearest, nearest.GetMaxHealth());
|
||||
|
||||
HitData hit = new HitData();
|
||||
hit.m_damage.m_damage = 99999f;
|
||||
hit.m_hitType = HitData.HitType.Undefined;
|
||||
hit.m_attacker = __instance.GetZDOID();
|
||||
nearest.ApplyDamage(hit, true, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
Jotunn.Logger.LogInfo("[AswidDebug] No mob found near player to consume.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[HarmonyPatch(typeof(Character), "Damage")]
|
||||
public static class Aswid_Damage_Patch
|
||||
{
|
||||
public static void Prefix(Character __instance, HitData hit, out float __state)
|
||||
{
|
||||
__state = (__instance != null) ? __instance.GetHealth() : 0f;
|
||||
}
|
||||
|
||||
public static void Postfix(Character __instance, HitData hit, float __state)
|
||||
{
|
||||
if (hit == null || __instance == null || __instance.IsPlayer()) return;
|
||||
|
||||
// Check if it died from this hit
|
||||
if (__state > 0f && __instance.GetHealth() <= 0f)
|
||||
{
|
||||
Jotunn.Logger.LogInfo($"[AswidDebug] {__instance.name} died. __state: {__state}, CurrentHP: {__instance.GetHealth()}");
|
||||
Character attacker = hit.GetAttacker();
|
||||
if (attacker != null) Jotunn.Logger.LogInfo($"[AswidDebug] Attacker is: {attacker.name} / Player: {attacker.IsPlayer()} / Local: {attacker == Player.m_localPlayer}");
|
||||
|
||||
if (attacker != null && attacker.IsPlayer() && attacker == Player.m_localPlayer)
|
||||
{
|
||||
ZNetView nview = attacker.GetComponent<ZNetView>();
|
||||
if (nview != null && nview.IsValid() && nview.GetZDO().GetString("RacesOfValheim_Race", "Human") == "Aswid")
|
||||
{
|
||||
Jotunn.Logger.LogInfo($"[AswidDebug] Attacker is local Aswid player. Checking damage type...");
|
||||
|
||||
// Check if physical attack
|
||||
if (hit.m_damage.m_blunt > 0 || hit.m_damage.m_slash > 0 || hit.m_damage.m_pierce > 0 || hit.m_damage.m_chop > 0 || hit.m_damage.m_pickaxe > 0 || hit.m_damage.m_damage > 0)
|
||||
{
|
||||
Jotunn.Logger.LogInfo($"[AswidDebug] Calling TryConsumeMob for {__instance.name}");
|
||||
AswidRace.TryConsumeMob(__instance, __instance.GetMaxHealth());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[HarmonyPatch(typeof(Player), "HaveEitr")]
|
||||
public static class Player_HaveEitr_Patch
|
||||
{
|
||||
public static void Postfix(Player __instance, ref bool __result)
|
||||
{
|
||||
if (__instance != null && __instance == Player.m_localPlayer && AswidRace.IsAswid())
|
||||
{
|
||||
var weapon = __instance.GetCurrentWeapon();
|
||||
if (weapon != null && weapon.m_shared != null && weapon.m_shared.m_skillType == Skills.SkillType.BloodMagic)
|
||||
{
|
||||
__result = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[HarmonyPatch(typeof(Player), "UseEitr")]
|
||||
public static class Player_UseEitr_Patch
|
||||
{
|
||||
public static bool Prefix(Player __instance)
|
||||
{
|
||||
if (__instance != null && __instance == Player.m_localPlayer && AswidRace.IsAswid())
|
||||
{
|
||||
var weapon = __instance.GetCurrentWeapon();
|
||||
if (weapon != null && weapon.m_shared != null && weapon.m_shared.m_skillType == Skills.SkillType.BloodMagic)
|
||||
{
|
||||
return false; // Skip spending Eitr
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
[HarmonyPatch(typeof(Skills), "RaiseSkill")]
|
||||
public static class Aswid_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 && AswidRace.IsAswid())
|
||||
{
|
||||
if (skillType == Skills.SkillType.BloodMagic)
|
||||
{
|
||||
factor *= 2f; // Benedictus et Afflictus: Double speed for Blood Magic
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[HarmonyPatch(typeof(Player), "UpdateFood")]
|
||||
public static class Aswid_PlayerUpdateFood_Patch
|
||||
{
|
||||
public static void Prefix(Player __instance, float dt, bool forceUpdate)
|
||||
{
|
||||
if (__instance != Player.m_localPlayer || !AswidRace.IsAswid()) return;
|
||||
|
||||
if (AswidFoodManager.ExtraFoods.TryGetValue(__instance, 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)
|
||||
{
|
||||
AswidFoodManager.ClearFood(__instance);
|
||||
}
|
||||
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 Aswid_PlayerGetTotalFoodValue_Patch
|
||||
{
|
||||
public static void Postfix(Player __instance, ref float hp, ref float stamina, ref float eitr)
|
||||
{
|
||||
if (__instance != Player.m_localPlayer || !AswidRace.IsAswid()) return;
|
||||
|
||||
if (AswidFoodManager.ExtraFoods.TryGetValue(__instance, out Player.Food extraFood) && extraFood != null)
|
||||
{
|
||||
hp += extraFood.m_health;
|
||||
stamina += extraFood.m_stamina;
|
||||
eitr += extraFood.m_eitr;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
62
JotunnModStub/Aswid/AswidProgression.cs
Normal file
62
JotunnModStub/Aswid/AswidProgression.cs
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace RacesOfValheim
|
||||
{
|
||||
public static class AswidProgression
|
||||
{
|
||||
public enum FormType
|
||||
{
|
||||
None,
|
||||
Bat
|
||||
}
|
||||
|
||||
public class FormRules
|
||||
{
|
||||
public FormType Form = FormType.None;
|
||||
public bool NeedsNight = false;
|
||||
}
|
||||
|
||||
public class AswidRules
|
||||
{
|
||||
// Add state 0 properties here
|
||||
public float BonusHealth = 0f;
|
||||
public float BonusStamina = 0f;
|
||||
public bool HasSurtlingForm = false;
|
||||
}
|
||||
|
||||
public static AswidRules GetRules(int state)
|
||||
{
|
||||
AswidRules rules = new AswidRules();
|
||||
|
||||
// State 0 is the base state, no modifiers yet.
|
||||
if (state >= 1)
|
||||
{
|
||||
// Future modifiers
|
||||
}
|
||||
|
||||
if (state >= 8) // Fader
|
||||
{
|
||||
rules.HasSurtlingForm = true;
|
||||
}
|
||||
|
||||
return rules;
|
||||
}
|
||||
|
||||
public static FormRules GetGKeyRules(int state)
|
||||
{
|
||||
FormRules rules = new FormRules();
|
||||
if (state >= 3)
|
||||
{
|
||||
rules.Form = FormType.Bat;
|
||||
rules.NeedsNight = false; // The Elder: always
|
||||
}
|
||||
else if (state >= 2)
|
||||
{
|
||||
rules.Form = FormType.Bat;
|
||||
rules.NeedsNight = true; // Eikthyr: night only
|
||||
}
|
||||
return rules.Form != FormType.None ? rules : null;
|
||||
}
|
||||
}
|
||||
}
|
||||
1182
JotunnModStub/Aswid/AswidRace.cs
Normal file
1182
JotunnModStub/Aswid/AswidRace.cs
Normal file
File diff suppressed because it is too large
Load diff
145
JotunnModStub/Aswid/AswidStatusEffects.cs
Normal file
145
JotunnModStub/Aswid/AswidStatusEffects.cs
Normal file
|
|
@ -0,0 +1,145 @@
|
|||
using Jotunn.Managers;
|
||||
using Jotunn.Entities;
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace RacesOfValheim
|
||||
{
|
||||
public class SE_AswidStats : SE_Stats
|
||||
{
|
||||
public override void Setup(Character character)
|
||||
{
|
||||
base.Setup(character);
|
||||
name = "SE_AswidStats";
|
||||
m_name = "Benedictus et Afflictus";
|
||||
m_tooltip = "Vampiric senses and life drain.";
|
||||
}
|
||||
|
||||
public void UpdateStats(int state)
|
||||
{
|
||||
m_fallDamageModifier = -1f; // No fall damage
|
||||
|
||||
float multiplier = (EnvMan.instance != null && EnvMan.IsNight()) ? 2f : 1f;
|
||||
|
||||
m_speedModifier = 0.01f * state * multiplier; // +3% speed per stage (*2 at night)
|
||||
|
||||
// For jump, Valheim SE_Stats typically adds the y value to 1
|
||||
m_jumpModifier = new Vector3(0f, 0.01f * state * multiplier, 0f);
|
||||
|
||||
if (state >= 5)
|
||||
{
|
||||
if (m_mods == null) m_mods = new System.Collections.Generic.List<HitData.DamageModPair>();
|
||||
m_mods.Clear(); // Refresh to avoid duplicates
|
||||
m_mods.Add(new HitData.DamageModPair() { m_type = HitData.DamageType.Poison, m_modifier = HitData.DamageModifier.Immune });
|
||||
}
|
||||
else
|
||||
{
|
||||
if (m_mods != null) m_mods.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
public override void ModifyAttack(Skills.SkillType skill, ref HitData hitData)
|
||||
{
|
||||
base.ModifyAttack(skill, ref hitData);
|
||||
if (m_character is Player p && p.GetComponent<ZNetView>() != null && p.GetComponent<ZNetView>().GetZDO() != null)
|
||||
{
|
||||
int state = BossProgressionManager.GetCurrentProgressionState();
|
||||
var rules = AswidProgression.GetRules(state);
|
||||
if (rules != null && rules.HasSurtlingForm)
|
||||
{
|
||||
hitData.m_damage.m_damage += 30f;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class SE_BatForm : SE_Stats
|
||||
{
|
||||
public override void Setup(Character character)
|
||||
{
|
||||
base.Setup(character);
|
||||
name = "SE_BatForm";
|
||||
m_name = "Like a Bat out of Hell";
|
||||
m_tooltip = "You have taken the form of a Bat. You can fly, but cannot attack.";
|
||||
m_fallDamageModifier = -1f; // Immune to fall damage just in case
|
||||
}
|
||||
}
|
||||
|
||||
public class SE_MistForm : SE_Stats
|
||||
{
|
||||
public override void Setup(Character character)
|
||||
{
|
||||
base.Setup(character);
|
||||
name = "SE_MistForm";
|
||||
m_name = "Weight of Shadows";
|
||||
m_tooltip = "You are mist. Immune to physical damage and poison. Cannot attack or run.";
|
||||
m_fallDamageModifier = -1f;
|
||||
m_mods = new System.Collections.Generic.List<HitData.DamageModPair>
|
||||
{
|
||||
new HitData.DamageModPair { m_type = HitData.DamageType.Blunt, m_modifier = HitData.DamageModifier.Immune },
|
||||
new HitData.DamageModPair { m_type = HitData.DamageType.Slash, m_modifier = HitData.DamageModifier.Immune },
|
||||
new HitData.DamageModPair { m_type = HitData.DamageType.Pierce, m_modifier = HitData.DamageModifier.Immune },
|
||||
new HitData.DamageModPair { m_type = HitData.DamageType.Poison, m_modifier = HitData.DamageModifier.Immune }
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public class SE_AswidSensesMark : SE_Stats
|
||||
{
|
||||
public override void Setup(Character character)
|
||||
{
|
||||
base.Setup(character);
|
||||
name = "SE_AswidSensesMark";
|
||||
m_name = "Sensed";
|
||||
m_tooltip = "";
|
||||
m_ttl = 2f;
|
||||
m_icon = null; // No icon needed for mobs
|
||||
}
|
||||
}
|
||||
|
||||
public class SE_SuperhumanSenses : SE_Stats
|
||||
{
|
||||
public override void Setup(Character character)
|
||||
{
|
||||
base.Setup(character);
|
||||
name = "SE_SuperhumanSenses";
|
||||
m_name = "Auspex";
|
||||
m_tooltip = "Sensing life force of nearby creatures.";
|
||||
}
|
||||
}
|
||||
|
||||
public class AswidStatusEffects
|
||||
{
|
||||
public static void RegisterStatusEffects()
|
||||
{
|
||||
var aswidStats = ScriptableObject.CreateInstance<SE_AswidStats>();
|
||||
aswidStats.name = "SE_AswidStats";
|
||||
aswidStats.m_icon = PrefabManager.Cache.GetPrefab<ItemDrop>("TrophyBat")?.m_itemData.m_shared.m_icons[0];
|
||||
|
||||
ItemManager.Instance.AddStatusEffect(new CustomStatusEffect(aswidStats, fixReference: false));
|
||||
|
||||
var batForm = ScriptableObject.CreateInstance<SE_BatForm>();
|
||||
batForm.name = "SE_BatForm";
|
||||
batForm.m_icon = PrefabManager.Cache.GetPrefab<ItemDrop>("TrophyBat")?.m_itemData.m_shared.m_icons[0];
|
||||
|
||||
ItemManager.Instance.AddStatusEffect(new CustomStatusEffect(batForm, fixReference: false));
|
||||
|
||||
var mistForm = ScriptableObject.CreateInstance<SE_MistForm>();
|
||||
mistForm.name = "SE_MistForm";
|
||||
mistForm.m_icon = PrefabManager.Cache.GetPrefab<ItemDrop>("TrophyWraith")?.m_itemData.m_shared.m_icons[0];
|
||||
|
||||
ItemManager.Instance.AddStatusEffect(new CustomStatusEffect(mistForm, fixReference: false));
|
||||
|
||||
var sensesMark = ScriptableObject.CreateInstance<SE_AswidSensesMark>();
|
||||
sensesMark.name = "SE_AswidSensesMark";
|
||||
sensesMark.m_name = "Sensed";
|
||||
sensesMark.m_ttl = 2f;
|
||||
ItemManager.Instance.AddStatusEffect(new CustomStatusEffect(sensesMark, fixReference: false));
|
||||
|
||||
var senses = ScriptableObject.CreateInstance<SE_SuperhumanSenses>();
|
||||
senses.name = "SE_SuperhumanSenses";
|
||||
senses.m_icon = PrefabManager.Cache.GetPrefab<ItemDrop>("TrophyWolf")?.m_itemData.m_shared.m_icons[0];
|
||||
ItemManager.Instance.AddStatusEffect(new CustomStatusEffect(senses, fixReference: false));
|
||||
}
|
||||
}
|
||||
}
|
||||
159
JotunnModStub/Aswid/AswidThrall.cs
Normal file
159
JotunnModStub/Aswid/AswidThrall.cs
Normal file
|
|
@ -0,0 +1,159 @@
|
|||
using UnityEngine;
|
||||
using System;
|
||||
|
||||
namespace RacesOfValheim
|
||||
{
|
||||
public class AswidThrall : MonoBehaviour, Interactable, Hoverable
|
||||
{
|
||||
private Character m_character;
|
||||
private MonsterAI m_ai;
|
||||
private ZNetView m_nview;
|
||||
private bool m_wasEnslaved = false;
|
||||
private bool m_wasConsumed = false;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
m_character = GetComponent<Character>();
|
||||
m_ai = GetComponent<MonsterAI>();
|
||||
m_nview = GetComponent<ZNetView>();
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (m_nview == null || !m_nview.IsValid()) return;
|
||||
|
||||
bool isEnslaved = m_nview.GetZDO().GetBool("AswidEnslaved", false);
|
||||
if (isEnslaved)
|
||||
{
|
||||
if (!m_wasEnslaved)
|
||||
{
|
||||
m_wasEnslaved = true;
|
||||
m_character.SetTamed(true); // Ensure tamed is true on client side if it missed the RPC
|
||||
|
||||
if (m_ai != null)
|
||||
{
|
||||
// Custom AI behaviors can be set here if needed
|
||||
}
|
||||
}
|
||||
|
||||
// If it dies, the local player who owns it tries to consume it
|
||||
if (m_character.IsDead() && !m_wasConsumed)
|
||||
{
|
||||
m_wasConsumed = true;
|
||||
if (m_nview.IsOwner() && AswidRace.IsAswid())
|
||||
{
|
||||
AswidRace.TryConsumeMob(m_character, m_character.GetMaxHealth());
|
||||
}
|
||||
}
|
||||
|
||||
// Only the ZDO owner should track lifetime to kill it
|
||||
if (m_nview.IsOwner())
|
||||
{
|
||||
long enslaveTime = m_nview.GetZDO().GetLong("AswidEnslaveTime", 0);
|
||||
if (enslaveTime > 0)
|
||||
{
|
||||
DateTime time = new DateTime(enslaveTime);
|
||||
if ((DateTime.Now - time).TotalSeconds >= 60.0)
|
||||
{
|
||||
// Time's up! Kill the thrall.
|
||||
HitData hit = new HitData();
|
||||
hit.m_damage.m_damage = 99999f;
|
||||
hit.m_hitType = HitData.HitType.Undefined;
|
||||
m_character.ApplyDamage(hit, true, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool Interact(Humanoid user, bool hold, bool alt)
|
||||
{
|
||||
if (hold || alt) return false;
|
||||
if (m_nview == null || !m_nview.IsValid()) return false;
|
||||
if (user != Player.m_localPlayer || !AswidRace.IsAswid()) return false;
|
||||
|
||||
bool isEnslaved = m_nview.GetZDO().GetBool("AswidEnslaved", false);
|
||||
if (isEnslaved)
|
||||
{
|
||||
// Toggle follow/stay
|
||||
if (m_ai != null)
|
||||
{
|
||||
if (m_ai.GetFollowTarget() == user.gameObject)
|
||||
{
|
||||
m_ai.SetFollowTarget(null);
|
||||
user.Message(MessageHud.MessageType.Center, $"{m_character.m_name} is staying.");
|
||||
}
|
||||
else
|
||||
{
|
||||
m_ai.SetFollowTarget(user.gameObject);
|
||||
user.Message(MessageHud.MessageType.Center, $"{m_character.m_name} is following.");
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// Enslave action
|
||||
if (BossProgressionManager.GetCurrentProgressionState() < 6) return false;
|
||||
|
||||
float cooldown = AswidRace.GetEnslaveCooldown();
|
||||
if (cooldown > 0)
|
||||
{
|
||||
user.Message(MessageHud.MessageType.Center, $"Dominate on cooldown ({Mathf.CeilToInt(cooldown / 60f)}m {Mathf.CeilToInt(cooldown % 60f)}s)");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Enslave it!
|
||||
AswidRace.StartEnslaveCooldown();
|
||||
|
||||
// Take ownership to set ZDO vars reliably
|
||||
m_nview.ClaimOwnership();
|
||||
|
||||
m_nview.GetZDO().Set("AswidEnslaved", true);
|
||||
m_nview.GetZDO().Set("AswidEnslaveTime", DateTime.Now.Ticks);
|
||||
m_character.SetTamed(true);
|
||||
|
||||
if (m_ai != null)
|
||||
{
|
||||
m_ai.SetFollowTarget(user.gameObject);
|
||||
}
|
||||
|
||||
GameObject vfx = ZNetScene.instance.GetPrefab("vfx_surtling_death");
|
||||
if (vfx) Instantiate(vfx, m_character.transform.position, Quaternion.identity);
|
||||
|
||||
user.Message(MessageHud.MessageType.Center, $"{m_character.m_name} dominated!");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool UseItem(Humanoid user, ItemDrop.ItemData item)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public string GetHoverText()
|
||||
{
|
||||
if (m_nview == null || !m_nview.IsValid()) return "";
|
||||
if (Player.m_localPlayer == null || !AswidRace.IsAswid()) return "";
|
||||
|
||||
bool isEnslaved = m_nview.GetZDO().GetBool("AswidEnslaved", false);
|
||||
if (isEnslaved)
|
||||
{
|
||||
bool following = m_ai != null && m_ai.GetFollowTarget() != null;
|
||||
return following ? "[<color=yellow><b>E</b></color>] Stay" : "[<color=yellow><b>E</b></color>] Follow";
|
||||
}
|
||||
else
|
||||
{
|
||||
if (BossProgressionManager.GetCurrentProgressionState() < 6) return "";
|
||||
|
||||
float cd = AswidRace.GetEnslaveCooldown();
|
||||
if (cd > 0) return $"[<color=red>E</color>] Dominate (Cooldown: {Mathf.CeilToInt(cd / 60f)}m)";
|
||||
return "[<color=yellow><b>E</b></color>] Dominate";
|
||||
}
|
||||
}
|
||||
|
||||
public string GetHoverName()
|
||||
{
|
||||
return ""; // Character component already provides the name
|
||||
}
|
||||
}
|
||||
}
|
||||
54
JotunnModStub/Aswid/BatFormBehavior.cs
Normal file
54
JotunnModStub/Aswid/BatFormBehavior.cs
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
using UnityEngine;
|
||||
using Jotunn.Managers;
|
||||
|
||||
namespace RacesOfValheim
|
||||
{
|
||||
public class BatFormBehavior : MonoBehaviour
|
||||
{
|
||||
private Animator anim;
|
||||
private AswidProgression.FormRules formRules;
|
||||
|
||||
public void Initialize(AswidProgression.FormRules rules)
|
||||
{
|
||||
this.formRules = rules;
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
anim = GetComponentInChildren<Animator>();
|
||||
if (Player.m_localPlayer != null)
|
||||
{
|
||||
HarmonyLib.Traverse.Create(Player.m_localPlayer).Field("m_debugFly").SetValue(true);
|
||||
}
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (Player.m_localPlayer == null || Player.m_localPlayer.IsDead()) return;
|
||||
|
||||
// Ensure flight remains on continuously
|
||||
HarmonyLib.Traverse.Create(Player.m_localPlayer).Field("m_debugFly").SetValue(true);
|
||||
|
||||
// Sync Animator
|
||||
if (anim != null)
|
||||
{
|
||||
Vector3 vel = Player.m_localPlayer.GetVelocity();
|
||||
vel.y = 0f;
|
||||
float speed = vel.magnitude;
|
||||
|
||||
// Bats don't necessarily have a complex animator like players,
|
||||
// but if they do have a speed or flying parameter, we set it here.
|
||||
anim.SetFloat("forward_speed", speed);
|
||||
anim.SetBool("flying", true);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
if (Player.m_localPlayer != null)
|
||||
{
|
||||
HarmonyLib.Traverse.Create(Player.m_localPlayer).Field("m_debugFly").SetValue(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue