102 lines
3.8 KiB
C#
102 lines
3.8 KiB
C#
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 * TrolConfig.UnarmedFarmingDamageBonusPerState.Value;
|
|
|
|
// 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);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// Patched on Damage (attacker side), not RPC_Damage: the RPC runs on the object owner (host), where the attacker is not the local player.
|
|
[HarmonyPatch(typeof(TreeBase), "Damage")]
|
|
public static class Trol_TreeBase_RPC_Damage_Patch
|
|
{
|
|
public static void Prefix(HitData hit)
|
|
{
|
|
TrolFarmingHelper.ApplyTrolUnarmedToolBuff(hit, true);
|
|
}
|
|
}
|
|
|
|
[HarmonyPatch(typeof(TreeLog), "Damage")]
|
|
public static class Trol_TreeLog_RPC_Damage_Patch
|
|
{
|
|
public static void Prefix(HitData hit)
|
|
{
|
|
TrolFarmingHelper.ApplyTrolUnarmedToolBuff(hit, true);
|
|
}
|
|
}
|
|
|
|
[HarmonyPatch(typeof(Destructible), "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), "Damage")]
|
|
public static class Trol_MineRock_RPC_Hit_Patch
|
|
{
|
|
public static void Prefix(HitData hit)
|
|
{
|
|
TrolFarmingHelper.ApplyTrolUnarmedToolBuff(hit, false);
|
|
}
|
|
}
|
|
|
|
[HarmonyPatch(typeof(MineRock5), "Damage")]
|
|
public static class Trol_MineRock5_DamageArea_Patch
|
|
{
|
|
public static void Prefix(HitData hit)
|
|
{
|
|
TrolFarmingHelper.ApplyTrolUnarmedToolBuff(hit, false);
|
|
}
|
|
}
|
|
}
|