162 lines
6.4 KiB
C#
162 lines
6.4 KiB
C#
using UnityEngine;
|
|
|
|
namespace RacesOfValheim
|
|
{
|
|
public class DraughRace : MonoBehaviour
|
|
{
|
|
public static DraughRace Instance;
|
|
|
|
private void Awake()
|
|
{
|
|
Instance = this;
|
|
}
|
|
|
|
public void CreateModAssets()
|
|
{
|
|
// Generate EdibleUncooked prefabs for Draugh raw food logic
|
|
foreach (var mapping in DraughFoodPatches.rawToCookedMapping)
|
|
{
|
|
string rawPrefabName = mapping.Key;
|
|
string cookedPrefabName = mapping.Value;
|
|
|
|
GameObject rawPrefab = Jotunn.Managers.PrefabManager.Cache.GetPrefab<GameObject>(rawPrefabName);
|
|
GameObject cookedPrefab = Jotunn.Managers.PrefabManager.Cache.GetPrefab<GameObject>(cookedPrefabName);
|
|
|
|
if (rawPrefab != null && cookedPrefab != null)
|
|
{
|
|
ItemDrop rawDrop = rawPrefab.GetComponent<ItemDrop>();
|
|
ItemDrop cookedDrop = cookedPrefab.GetComponent<ItemDrop>();
|
|
|
|
if (rawDrop != null && cookedDrop != null)
|
|
{
|
|
string customName = "EdibleUncooked_" + rawPrefabName;
|
|
Jotunn.Entities.CustomItem customItem = new Jotunn.Entities.CustomItem(customName, cookedPrefabName);
|
|
|
|
ItemDrop customDrop = customItem.ItemDrop;
|
|
customDrop.m_itemData.m_shared.m_name = rawDrop.m_itemData.m_shared.m_name;
|
|
customDrop.m_itemData.m_shared.m_description = rawDrop.m_itemData.m_shared.m_description;
|
|
customDrop.m_itemData.m_shared.m_icons = rawDrop.m_itemData.m_shared.m_icons;
|
|
customDrop.m_itemData.m_shared.m_foodBurnTime *= 1.5f;
|
|
|
|
Jotunn.Managers.ItemManager.Instance.AddItem(customItem);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public static bool IsDraugh()
|
|
{
|
|
return Player.m_localPlayer != null &&
|
|
Player.m_localPlayer.m_customData.ContainsKey("Race") &&
|
|
Player.m_localPlayer.m_customData["Race"] == "Draugh";
|
|
}
|
|
|
|
private GameObject draughVFX = null;
|
|
private float foodCheckTimer = 0f;
|
|
private int lastProgressionState = -1;
|
|
|
|
private void Update()
|
|
{
|
|
if (Player.m_localPlayer == null) return;
|
|
|
|
if (IsDraugh() && !Player.m_localPlayer.IsDead())
|
|
{
|
|
EnsureVFX(true);
|
|
|
|
foodCheckTimer += Time.deltaTime;
|
|
if (foodCheckTimer >= 2f)
|
|
{
|
|
foodCheckTimer = 0f;
|
|
int currentState = BossProgressionManager.GetCurrentProgressionState();
|
|
if (currentState != lastProgressionState)
|
|
{
|
|
lastProgressionState = currentState;
|
|
UpdateFoodEitr(currentState >= 6); // 6 = Yagluth Defeated
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
EnsureVFX(false);
|
|
}
|
|
}
|
|
|
|
private void UpdateFoodEitr(bool enableEitr)
|
|
{
|
|
if (ObjectDB.instance == null) return;
|
|
|
|
foreach (var mapping in DraughFoodPatches.rawToCookedMapping)
|
|
{
|
|
string customPrefabName = "EdibleUncooked_" + mapping.Key;
|
|
GameObject customPrefab = ObjectDB.instance.GetItemPrefab(customPrefabName);
|
|
if (customPrefab != null)
|
|
{
|
|
ItemDrop drop = customPrefab.GetComponent<ItemDrop>();
|
|
if (drop != null && drop.m_itemData != null && drop.m_itemData.m_shared != null)
|
|
{
|
|
if (enableEitr)
|
|
{
|
|
drop.m_itemData.m_shared.m_foodEitr = drop.m_itemData.m_shared.m_food / 2f;
|
|
}
|
|
else
|
|
{
|
|
drop.m_itemData.m_shared.m_foodEitr = 0f;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private void EnsureVFX(bool enable)
|
|
{
|
|
if (enable && Player.m_localPlayer != null)
|
|
{
|
|
if (draughVFX == null)
|
|
{
|
|
GameObject draugrPrefab = Jotunn.Managers.PrefabManager.Cache.GetPrefab<GameObject>("Draugr");
|
|
if (draugrPrefab != null)
|
|
{
|
|
draughVFX = new GameObject("DraughAuraVFX");
|
|
draughVFX.transform.SetParent(Player.m_localPlayer.transform, false);
|
|
draughVFX.transform.localPosition = new Vector3(0, 1f, 0);
|
|
|
|
// Find all ParticleSystems in Draugr prefab
|
|
ParticleSystem[] pss = draugrPrefab.GetComponentsInChildren<ParticleSystem>(true);
|
|
foreach (ParticleSystem ps in pss)
|
|
{
|
|
// We only want looping ambient effects (flies, smoke)
|
|
if (ps.main.loop)
|
|
{
|
|
GameObject psCopy = Instantiate(ps.gameObject, draughVFX.transform);
|
|
psCopy.name = ps.gameObject.name;
|
|
psCopy.SetActive(true);
|
|
|
|
// Ensure it's positioned correctly
|
|
psCopy.transform.localPosition = ps.transform.localPosition;
|
|
psCopy.transform.localRotation = ps.transform.localRotation;
|
|
|
|
// Make the green smoke 50% larger. We exclude "flies" in case they are separate.
|
|
if (!psCopy.name.ToLower().Contains("flies"))
|
|
{
|
|
psCopy.transform.localScale = ps.transform.localScale * 1.5f;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
if (draughVFX != null && !draughVFX.activeSelf)
|
|
{
|
|
draughVFX.SetActive(true);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (draughVFX != null && draughVFX.activeSelf)
|
|
{
|
|
draughVFX.SetActive(false);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|