Initial commit
This commit is contained in:
commit
c4a24c9fdf
142 changed files with 15491 additions and 0 deletions
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue