fix(trol): True Form troll size, log, reach, root during attacks, slam
The troll pulsed several times a second and stayed small because PlayerVisualHider.Hide put the hidden Visual back to scale 1 every frame while Trol_PlayerUpdate_Patch grew it back, and the troll follows that scale. Hide and Show take keepScale now, and the Trol calls pass it. The camera height, which reads the same scale, stops jumping too. The log in the troll's hand is the troll's own log model, hung the way VisEquipment does it, instead of the Trol's, which was built for a person's hand and came out huge and sideways. Punch and slam reach further and hit wider, with a new Troll Attack Reach option (1.3). The player is held still through every attack clip, throw included. The ground slam spawns the troll's own troll_groundslam_aoe with the player's damage, kept off friends, plus its trigger and terrain effects. It carries chop and pickaxe at least equal to its blunt, so it breaks trees and rocks, and with Ground Slam Crater on it digs into the terrain where it lands, never inside a ward without access.
This commit is contained in:
parent
c64cb393c7
commit
db29f868ea
4 changed files with 190 additions and 33 deletions
|
|
@ -33,6 +33,17 @@ namespace RacesOfValheim
|
|||
|
||||
public bool IsAttacking => isAttacking;
|
||||
|
||||
private void SetAttacking(bool on)
|
||||
{
|
||||
isAttacking = on;
|
||||
TrolTrueFormModel.LocalAttacking = on;
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
TrolTrueFormModel.LocalAttacking = false;
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
anim = GetComponentInChildren<Animator>();
|
||||
|
|
@ -54,7 +65,7 @@ namespace RacesOfValheim
|
|||
{
|
||||
Player player = Player.m_localPlayer;
|
||||
if (player == null) return;
|
||||
PlayerVisualHider.Hide(player.transform.Find("Visual"), "trol-trueform-local");
|
||||
PlayerVisualHider.Hide(player.transform.Find("Visual"), "trol-trueform-local", keepScale: true);
|
||||
}
|
||||
|
||||
private void Update()
|
||||
|
|
@ -70,7 +81,7 @@ namespace RacesOfValheim
|
|||
if (FormAnimGuard.Stuck(isAttacking, ref busySince))
|
||||
{
|
||||
StopAllCoroutines();
|
||||
isAttacking = false;
|
||||
SetAttacking(false);
|
||||
}
|
||||
|
||||
if (isAttacking || player.IsDead()) return;
|
||||
|
|
@ -117,15 +128,15 @@ namespace RacesOfValheim
|
|||
|
||||
private IEnumerator ThrowRoutine(TrolTrueFormModel.Profile profile)
|
||||
{
|
||||
isAttacking = true;
|
||||
SetAttacking(true);
|
||||
Fire(profile.Trigger);
|
||||
yield return WaitForClip();
|
||||
isAttacking = false;
|
||||
SetAttacking(false);
|
||||
}
|
||||
|
||||
private IEnumerator AttackRoutine(TrolTrueFormModel.Profile profile, bool log)
|
||||
{
|
||||
isAttacking = true;
|
||||
SetAttacking(true);
|
||||
Player player = Player.m_localPlayer;
|
||||
|
||||
int baseline = TrolTrueFormModel.AttackEvents;
|
||||
|
|
@ -140,8 +151,18 @@ namespace RacesOfValheim
|
|||
|
||||
if (player != null && !player.IsDead())
|
||||
{
|
||||
profile.Shared.m_triggerEffect.Create(player.transform.position, player.transform.rotation, player.transform);
|
||||
int landed = TrolTrueFormHit.Sweep(player, profile, transform.localScale.x);
|
||||
float scale = transform.localScale.x;
|
||||
int landed;
|
||||
if (profile.Type == Attack.AttackType.Area)
|
||||
{
|
||||
landed = TrolTrueFormHit.Slam(player, profile, scale);
|
||||
}
|
||||
else
|
||||
{
|
||||
profile.Shared.m_triggerEffect.Create(player.transform.position, player.transform.rotation, player.transform);
|
||||
landed = TrolTrueFormHit.Sweep(player, profile, scale);
|
||||
}
|
||||
|
||||
if (landed > 0)
|
||||
{
|
||||
player.RaiseSkill(Skills.SkillType.Clubs, 1f);
|
||||
|
|
@ -150,7 +171,7 @@ namespace RacesOfValheim
|
|||
}
|
||||
|
||||
yield return WaitForClip(Time.time - started);
|
||||
isAttacking = false;
|
||||
SetAttacking(false);
|
||||
}
|
||||
|
||||
private void Fire(string trigger)
|
||||
|
|
@ -206,24 +227,115 @@ namespace RacesOfValheim
|
|||
"piece_nonsolid", "terrain", "character", "character_net", "character_ghost", "hitbox",
|
||||
"character_noenv", "vehicle");
|
||||
|
||||
private const string SlamAoeFallback = "troll_groundslam_aoe";
|
||||
private const string CraterPrefab = "digg_v3";
|
||||
|
||||
private static readonly int GroundMask = LayerMask.GetMask("terrain", "Default", "static_solid", "piece");
|
||||
|
||||
/// <summary>
|
||||
/// The ground slam, done the way the troll does it: its attack's own spawn-on-trigger, the
|
||||
/// troll_groundslam_aoe that carries the dust and the area hit. Set up with this player's
|
||||
/// damage instead of the troll's (m_useAttackSettings) and kept off friends. The first
|
||||
/// version swept a sphere and spawned nothing, so a slam that hit no creature looked like
|
||||
/// nothing had happened at all.
|
||||
///
|
||||
/// It also breaks things: the slam's damage gets chop and pickaxe at least equal to its
|
||||
/// blunt, so trees, rocks and ore around the fists take the blow. With Ground Slam Crater on,
|
||||
/// the ground gives way too - a pickaxe's dig, which TerrainOp does not check against wards on
|
||||
/// its own, so the ward check is done here.
|
||||
/// </summary>
|
||||
/// <returns>1 if the slam went off, so the caller raises the skill; the AoE does its own hits.</returns>
|
||||
public static int Slam(Player player, TrolTrueFormModel.Profile profile, float costumeScale)
|
||||
{
|
||||
float range = Mathf.Max(2f, profile.Range * costumeScale * TrolConfig.TrueFormAttackReach.Value);
|
||||
Vector3 impact = player.transform.position + player.transform.forward * (range * 0.5f);
|
||||
|
||||
// Down onto whatever is under the fists, so the dust and the crater sit on the ground.
|
||||
bool onTerrain = false;
|
||||
if (Physics.Raycast(impact + Vector3.up * 3f, Vector3.down, out RaycastHit ground, 8f, GroundMask))
|
||||
{
|
||||
impact = ground.point;
|
||||
onTerrain = ground.collider != null && ground.collider.GetComponent<Heightmap>() != null;
|
||||
}
|
||||
|
||||
HitData.DamageTypes damage = TrolTrueFormModel.DamageFor(player, profile);
|
||||
damage.m_chop = Mathf.Max(damage.m_chop, damage.m_blunt);
|
||||
damage.m_pickaxe = Mathf.Max(damage.m_pickaxe, damage.m_blunt);
|
||||
|
||||
HitData hitData = new HitData();
|
||||
hitData.m_damage = damage;
|
||||
hitData.m_pushForce = profile.PushForce;
|
||||
hitData.m_skill = Skills.SkillType.Clubs;
|
||||
hitData.m_toolTier = (short)profile.ToolTier;
|
||||
hitData.m_dodgeable = true;
|
||||
hitData.m_blockable = true;
|
||||
hitData.m_hitType = HitData.HitType.PlayerHit;
|
||||
hitData.SetAttacker(player);
|
||||
|
||||
profile.Shared.m_triggerEffect.Create(impact, player.transform.rotation);
|
||||
profile.Shared.m_hitTerrainEffect.Create(impact, Quaternion.identity);
|
||||
|
||||
GameObject aoePrefab = profile.Shared.m_attack.m_spawnOnTrigger;
|
||||
if (aoePrefab == null) aoePrefab = Jotunn.Managers.PrefabManager.Cache.GetPrefab<GameObject>(SlamAoeFallback);
|
||||
|
||||
bool spawned = false;
|
||||
if (aoePrefab != null)
|
||||
{
|
||||
GameObject instance = Object.Instantiate(aoePrefab, impact, Quaternion.identity);
|
||||
Aoe aoe = instance.GetComponent<Aoe>();
|
||||
if (aoe != null)
|
||||
{
|
||||
aoe.m_useAttackSettings = true;
|
||||
aoe.m_hitFriendly = false;
|
||||
aoe.m_hitOwner = false;
|
||||
aoe.m_hitProps = true;
|
||||
aoe.m_radius = Mathf.Max(aoe.m_radius, range * 0.6f);
|
||||
aoe.Setup(player, player.transform.forward, -1f, hitData, null, null);
|
||||
spawned = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
Object.Destroy(instance);
|
||||
}
|
||||
}
|
||||
|
||||
// No Aoe to borrow: the sphere, centred on the impact, so the slam still hits.
|
||||
if (!spawned) SphereHit(player, impact + Vector3.up, range * 0.7f, 180f, damage, profile);
|
||||
|
||||
if (TrolConfig.TrueFormSlamCrater.Value && onTerrain && PrivateArea.CheckAccess(impact, 0f, false))
|
||||
{
|
||||
GameObject crater = Jotunn.Managers.PrefabManager.Cache.GetPrefab<GameObject>(CraterPrefab);
|
||||
if (crater != null) Object.Instantiate(crater, impact, Quaternion.identity);
|
||||
}
|
||||
|
||||
Jotunn.Logger.LogInfo($"[Trol] Ground slam: aoe '{aoePrefab?.name ?? "none"}' spawned={spawned}, " +
|
||||
$"range {range:0.0}, onTerrain={onTerrain}.");
|
||||
return 1;
|
||||
}
|
||||
|
||||
/// <returns>How many things the blow landed on.</returns>
|
||||
public static int Sweep(Player player, TrolTrueFormModel.Profile profile, float costumeScale)
|
||||
{
|
||||
Vector3 pos = player.transform.position;
|
||||
Vector3 forward = player.transform.forward;
|
||||
float range = Mathf.Max(1.5f, profile.Range * costumeScale);
|
||||
bool area = profile.Type == Attack.AttackType.Area;
|
||||
float range = Mathf.Max(2f, profile.Range * costumeScale * TrolConfig.TrueFormAttackReach.Value);
|
||||
|
||||
Vector3 center = area
|
||||
? pos + forward * (range * 0.3f) + Vector3.up
|
||||
: pos + forward * (range * 0.5f) + Vector3.up * Mathf.Max(1f, profile.Height * costumeScale);
|
||||
float radius = area ? range * 0.7f : range * 0.5f + 0.5f;
|
||||
float halfAngle = area ? 180f : Mathf.Max(60f, profile.Angle * 0.5f);
|
||||
Vector3 center = pos + forward * (range * 0.55f) + Vector3.up * Mathf.Max(1f, profile.Height * costumeScale);
|
||||
float radius = range * 0.6f + 0.75f;
|
||||
float halfAngle = Mathf.Max(75f, profile.Angle * 0.5f);
|
||||
|
||||
return SphereHit(player, center, radius, halfAngle, TrolTrueFormModel.DamageFor(player, profile), profile);
|
||||
}
|
||||
|
||||
private static int SphereHit(Player player, Vector3 center, float radius, float halfAngle,
|
||||
HitData.DamageTypes damage, TrolTrueFormModel.Profile profile)
|
||||
{
|
||||
Vector3 pos = player.transform.position;
|
||||
Vector3 forward = player.transform.forward;
|
||||
|
||||
Collider[] hits = Physics.OverlapSphere(center, radius, Mask);
|
||||
FormMelee.LogSwing(FormLabel, hits.Length);
|
||||
|
||||
HitData.DamageTypes damage = TrolTrueFormModel.DamageFor(player, profile);
|
||||
var done = new HashSet<GameObject>();
|
||||
int landed = 0;
|
||||
|
||||
|
|
@ -298,7 +410,7 @@ namespace RacesOfValheim
|
|||
private void LateUpdate()
|
||||
{
|
||||
if (player == null) return;
|
||||
PlayerVisualHider.Hide(player.transform.Find("Visual"), "trol-trueform-remote");
|
||||
PlayerVisualHider.Hide(player.transform.Find("Visual"), "trol-trueform-remote", keepScale: true);
|
||||
}
|
||||
|
||||
private void Update()
|
||||
|
|
@ -381,7 +493,7 @@ namespace RacesOfValheim
|
|||
{
|
||||
existing.gameObject.SetActive(false);
|
||||
Object.Destroy(existing.gameObject);
|
||||
PlayerVisualHider.Show(playerVisual, "trol-trueform-remote-revert");
|
||||
PlayerVisualHider.Show(playerVisual, "trol-trueform-remote-revert", keepScale: true);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
|
@ -393,7 +505,7 @@ namespace RacesOfValheim
|
|||
model.AddComponent<RemoteTrolTrueFormAnimator>();
|
||||
}
|
||||
|
||||
PlayerVisualHider.Hide(playerVisual, "trol-trueform-remote");
|
||||
PlayerVisualHider.Hide(playerVisual, "trol-trueform-remote", keepScale: true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue