1063 lines
44 KiB
C#
1063 lines
44 KiB
C#
using System.Collections;
|
|
using BepInEx;
|
|
using HarmonyLib;
|
|
using Jotunn.Configs;
|
|
using Jotunn.Entities;
|
|
using Jotunn.Managers;
|
|
using UnityEngine;
|
|
using UnityEngine.UI; // Added for UI
|
|
|
|
namespace RacesOfValheim
|
|
{
|
|
/// <summary>
|
|
/// Howl vocalisation, borrowed from the real creature instead of guessed at. Wolves and their
|
|
/// kin do not carry a standalone "sfx_wolf_howl"-style prefab that PlaySFX's
|
|
/// PrefabManager.Cache lookup could ever find - dumpdverger's own hierarchy dump for
|
|
/// Fenring_Cultist shows no ZSFX anywhere on it.
|
|
///
|
|
/// BaseAI.m_idleSound was the first guess and was wrong in a quieter way: it is real, but it
|
|
/// is the creature's passive ambient noise (DoIdleSound, on a timer while it is doing nothing
|
|
/// in particular) - a small grunt, not a howl, and it played back sounding like whatever
|
|
/// generic "the form did something" cue the transformation itself already uses. What a
|
|
/// creature actually vocalises WHEN IT SPOTS SOMETHING is BaseAI.m_alertedEffects, fired from
|
|
/// SetAlerted(true) - reading that off the real "Fenring"/"Fenring_Cultist" prefab and calling
|
|
/// Create() plays the same aggressive bark the creature itself makes going on alert.
|
|
/// </summary>
|
|
internal static class FenrirCreatureSound
|
|
{
|
|
public static void PlayHowl(string sourcePrefabName, Vector3 position)
|
|
{
|
|
GameObject source = PrefabManager.Cache.GetPrefab<GameObject>(sourcePrefabName);
|
|
BaseAI ai = source != null ? source.GetComponent<BaseAI>() : null;
|
|
if (ai == null || ai.m_alertedEffects == null)
|
|
{
|
|
Jotunn.Logger.LogWarning($"[FenrirForm] No BaseAI.m_alertedEffects found on '{sourcePrefabName}'.");
|
|
return;
|
|
}
|
|
|
|
ai.m_alertedEffects.Create(position, Quaternion.identity);
|
|
}
|
|
}
|
|
|
|
public class FenrirFormBehavior : MonoBehaviour
|
|
{
|
|
private Animator playerAnim;
|
|
private Animator fenrirAnim;
|
|
|
|
private bool isAttacking = false;
|
|
|
|
void Start()
|
|
{
|
|
playerAnim = Player.m_localPlayer.transform.Find("Visual").GetComponent<Animator>();
|
|
fenrirAnim = GetComponent<Animator>();
|
|
|
|
if (fenrirAnim == null) fenrirAnim = GetComponentInChildren<Animator>();
|
|
}
|
|
|
|
void Update()
|
|
{
|
|
if (playerAnim == null || fenrirAnim == null) return;
|
|
|
|
// Se stiamo attaccando, l'Update smette di inviare costantemente
|
|
// "onGround", inWater, forward_speed ecc. alle variabili di base?
|
|
// Meglio continuare a sincronizzare i movimenti base.
|
|
if (!isAttacking)
|
|
{
|
|
bool isGrounded = playerAnim.GetBool("onGround");
|
|
|
|
fenrirAnim.SetBool("onGround", isGrounded);
|
|
fenrirAnim.SetBool("inWater", playerAnim.GetBool("inWater"));
|
|
|
|
if (!isGrounded)
|
|
{
|
|
fenrirAnim.SetFloat("forward_speed", 0f);
|
|
fenrirAnim.SetFloat("sideway_speed", 0f);
|
|
}
|
|
else
|
|
{
|
|
if (Player.m_localPlayer.IsCrouching())
|
|
{
|
|
fenrirAnim.SetFloat("forward_speed", 0f);
|
|
fenrirAnim.SetFloat("sideway_speed", 0f);
|
|
}
|
|
else
|
|
{
|
|
fenrirAnim.SetFloat("forward_speed", playerAnim.GetFloat("forward_speed"));
|
|
fenrirAnim.SetFloat("sideway_speed", playerAnim.GetFloat("sideway_speed"));
|
|
}
|
|
}
|
|
if (isGrounded && RaceInput.Allowed)
|
|
{
|
|
if (FenrirConfig.HowlKey.Value.IsDownIgnoringHeldKeys())
|
|
{
|
|
StartCoroutine(HowlRoutine());
|
|
}
|
|
else if (RaceInput.AttackDown(1)) // Tasto destro (Heavy Claw)
|
|
{
|
|
StartCoroutine(ClawRoutine("attack_claw1", FenrirConfig.FenringHeavyClawDamage.Value, 1.2f, 0.5f));
|
|
}
|
|
else if (RaceInput.AttackDown(0)) // Tasto sinistro
|
|
{
|
|
StartCoroutine(ClawRoutine("attack_claw0", FenrirConfig.FenringLightClawDamage.Value, 1.0f, 0.4f));
|
|
}
|
|
else if (RaceInput.AttackDown(2)) // Tasto centrale
|
|
{
|
|
StartCoroutine(JumpAttackRoutine());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private void PlaySFX(params string[] prefabNames)
|
|
{
|
|
foreach (string name in prefabNames)
|
|
{
|
|
GameObject sfx = PrefabManager.Cache.GetPrefab<GameObject>(name);
|
|
if (sfx != null)
|
|
{
|
|
Instantiate(sfx, Player.m_localPlayer.transform.position, Quaternion.identity);
|
|
return;
|
|
}
|
|
}
|
|
Jotunn.Logger.LogWarning($"[FenrirForm] Nessun suono trovato tra: {string.Join(", ", prefabNames)}");
|
|
}
|
|
|
|
private IEnumerator HowlRoutine()
|
|
{
|
|
isAttacking = true;
|
|
|
|
fenrirAnim.SetFloat("forward_speed", 0f);
|
|
fenrirAnim.SetFloat("sideway_speed", 0f);
|
|
|
|
fenrirAnim.SetTrigger("attack_taunt");
|
|
|
|
FenrirCreatureSound.PlayHowl("Fenring", Player.m_localPlayer.transform.position);
|
|
|
|
yield return new WaitForSeconds(2.0f);
|
|
|
|
isAttacking = false;
|
|
}
|
|
|
|
private IEnumerator ClawRoutine(string triggerName, float baseDamage, float lockDuration, float dmgDelay)
|
|
{
|
|
isAttacking = true;
|
|
|
|
fenrirAnim.SetFloat("forward_speed", 0f);
|
|
fenrirAnim.SetFloat("sideway_speed", 0f);
|
|
|
|
fenrirAnim.SetTrigger(triggerName);
|
|
PlaySFX("sfx_fenring_attack", "sfx_fenring_attack_claw", "sfx_wolf_attack");
|
|
|
|
yield return new WaitForSeconds(dmgDelay);
|
|
|
|
if (ZNetScene.instance != null)
|
|
{
|
|
GameObject attackSfx = ZNetScene.instance.GetPrefab("sfx_fenring_attack");
|
|
if (attackSfx != null)
|
|
{
|
|
Instantiate(attackSfx, Player.m_localPlayer.transform.position, Quaternion.identity);
|
|
}
|
|
}
|
|
|
|
ExecuteClawDamage(baseDamage);
|
|
|
|
float remainingTimeToIdle = lockDuration - dmgDelay;
|
|
if (remainingTimeToIdle > 0)
|
|
{
|
|
yield return new WaitForSeconds(remainingTimeToIdle);
|
|
}
|
|
|
|
fenrirAnim.ResetTrigger(triggerName);
|
|
isAttacking = false;
|
|
}
|
|
|
|
private IEnumerator JumpAttackRoutine()
|
|
{
|
|
isAttacking = true;
|
|
|
|
fenrirAnim.SetFloat("forward_speed", 0f);
|
|
fenrirAnim.SetFloat("sideway_speed", 0f);
|
|
|
|
fenrirAnim.SetTrigger("attack_jump");
|
|
|
|
// Aspettiamo che l'animazione si carichi (0.75s)
|
|
yield return new WaitForSeconds(0.75f);
|
|
|
|
if (ZNetScene.instance != null)
|
|
{
|
|
GameObject attackSfx = ZNetScene.instance.GetPrefab("sfx_fenring_attack");
|
|
if (attackSfx != null)
|
|
{
|
|
Instantiate(attackSfx, Player.m_localPlayer.transform.position, Quaternion.identity);
|
|
}
|
|
}
|
|
|
|
// Invece di una singola spinta di velocità (che viene subito annullata da Valheim),
|
|
// muoviamo esplicitamente il personaggio fotogramma per fotogramma per 0.2 secondi
|
|
float dashDuration = 0.2f;
|
|
float elapsedDash = 0f;
|
|
while (elapsedDash < dashDuration)
|
|
{
|
|
if (Player.m_localPlayer != null)
|
|
{
|
|
Rigidbody rb = Player.m_localPlayer.GetComponent<Rigidbody>();
|
|
if (rb != null)
|
|
{
|
|
Vector3 dashVelocity = Player.m_localPlayer.transform.forward * FenrirConfig.FenringJumpDashSpeed.Value;
|
|
// Spinta verso l'alto solo nella prima metà dello scatto
|
|
if (elapsedDash < dashDuration / 2f)
|
|
{
|
|
dashVelocity += Vector3.up * FenrirConfig.FenringJumpDashUpwardSpeed.Value;
|
|
}
|
|
|
|
rb.MovePosition(rb.position + dashVelocity * Time.fixedDeltaTime);
|
|
}
|
|
}
|
|
elapsedDash += Time.fixedDeltaTime;
|
|
yield return new WaitForFixedUpdate();
|
|
}
|
|
|
|
// Infliggiamo il danno al termine dello scatto
|
|
ExecuteClawDamage(FenrirConfig.FenringJumpAttackDamage.Value);
|
|
|
|
// Tempo per riprendersi dall'atterraggio prima di potersi muovere di nuovo
|
|
yield return new WaitForSeconds(0.55f);
|
|
|
|
fenrirAnim.ResetTrigger("attack_jump");
|
|
isAttacking = false;
|
|
}
|
|
|
|
private void ExecuteClawDamage(float baseDamage)
|
|
{
|
|
if (Player.m_localPlayer == null) return;
|
|
|
|
Vector3 playerPos = Player.m_localPlayer.transform.position;
|
|
Vector3 attackPoint = playerPos + Player.m_localPlayer.transform.forward * 1.5f + Vector3.up * 1f;
|
|
float attackRadius = FenrirConfig.FenringAttackRadius.Value;
|
|
|
|
float unarmedSkillLevel = Player.m_localPlayer.GetSkillLevel(Skills.SkillType.Unarmed);
|
|
float totalDamage = baseDamage + unarmedSkillLevel;
|
|
|
|
int layerMask = LayerMask.GetMask("Default", "static_solid", "Default_small", "piece", "piece_nonsolid", "terrain", "character", "character_net", "character_ghost", "hitbox", "character_noenv", "vehicle");
|
|
|
|
Collider[] hits = Physics.OverlapSphere(attackPoint, attackRadius, layerMask);
|
|
System.Collections.Generic.HashSet<GameObject> hitObjects = new System.Collections.Generic.HashSet<GameObject>();
|
|
|
|
foreach (Collider hit in hits)
|
|
{
|
|
if (hit.gameObject == Player.m_localPlayer.gameObject) continue;
|
|
if (hit.attachedRigidbody != null && hit.attachedRigidbody.gameObject == Player.m_localPlayer.gameObject) continue;
|
|
|
|
IDestructible target = hit.GetComponentInParent<IDestructible>();
|
|
|
|
if (target != null)
|
|
{
|
|
Character characterTarget = target as Character;
|
|
if (characterTarget != null && characterTarget == Player.m_localPlayer) continue;
|
|
|
|
GameObject targetObj = (target as MonoBehaviour)?.gameObject;
|
|
if (targetObj != null)
|
|
{
|
|
if (hitObjects.Contains(targetObj)) continue;
|
|
hitObjects.Add(targetObj);
|
|
}
|
|
|
|
Vector3 targetCenter = hit.bounds.center;
|
|
Vector3 dirToTarget = (targetCenter - playerPos).normalized;
|
|
|
|
float angle = Vector3.Angle(Player.m_localPlayer.transform.forward, dirToTarget);
|
|
if (angle < 70f)
|
|
{
|
|
Vector3 eyePos = playerPos + Vector3.up * 1.5f;
|
|
if (!Physics.Linecast(eyePos, targetCenter, out RaycastHit rayHit, LayerMask.GetMask("Default", "static_solid", "terrain", "piece")))
|
|
{
|
|
HitData hitData = new HitData();
|
|
hitData.m_damage.m_slash = totalDamage;
|
|
hitData.m_pushForce = FenrirConfig.FenringPushForce.Value;
|
|
hitData.m_point = targetCenter;
|
|
hitData.m_dir = Player.m_localPlayer.transform.forward;
|
|
hitData.m_skill = Skills.SkillType.Unarmed;
|
|
hitData.m_dodgeable = true;
|
|
hitData.m_blockable = true;
|
|
hitData.m_hitType = HitData.HitType.PlayerHit;
|
|
hitData.m_toolTier = 0;
|
|
hitData.SetAttacker(Player.m_localPlayer);
|
|
|
|
target.Damage(hitData);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// --- CLASSE CUSTOM PER L'ATTACCO "FIRE" DEL CULTIST ---
|
|
public class CultistFormBehavior : MonoBehaviour
|
|
{
|
|
private Animator playerAnim;
|
|
private Animator cultistAnim;
|
|
|
|
private bool isAttacking = false;
|
|
private bool isShootingFire = false;
|
|
private float fireTimer = 0f;
|
|
|
|
void Start()
|
|
{
|
|
playerAnim = Player.m_localPlayer.transform.Find("Visual").GetComponent<Animator>();
|
|
cultistAnim = GetComponent<Animator>();
|
|
|
|
if (cultistAnim == null) cultistAnim = GetComponentInChildren<Animator>();
|
|
}
|
|
void Update()
|
|
{
|
|
if (playerAnim == null || cultistAnim == null) return;
|
|
|
|
if (!isAttacking)
|
|
{
|
|
bool isGrounded = playerAnim.GetBool("onGround");
|
|
|
|
cultistAnim.SetBool("onGround", isGrounded);
|
|
cultistAnim.SetBool("inWater", playerAnim.GetBool("inWater"));
|
|
|
|
if (!isGrounded)
|
|
{
|
|
cultistAnim.SetFloat("forward_speed", 0f);
|
|
cultistAnim.SetFloat("sideway_speed", 0f);
|
|
}
|
|
else
|
|
{
|
|
// Se tiene premuto Ctrl (Crouch), rallenta o ferma il movimento per preparare l'attacco
|
|
if (Player.m_localPlayer.IsCrouching())
|
|
{
|
|
cultistAnim.SetFloat("forward_speed", 0f);
|
|
cultistAnim.SetFloat("sideway_speed", 0f);
|
|
}
|
|
else
|
|
{
|
|
cultistAnim.SetFloat("forward_speed", playerAnim.GetFloat("forward_speed"));
|
|
cultistAnim.SetFloat("sideway_speed", playerAnim.GetFloat("sideway_speed"));
|
|
}
|
|
}
|
|
|
|
if (isGrounded)
|
|
{
|
|
// Gated per-read rather than around the block, so opening a GUI mid-stream
|
|
// still falls through to StopFire() instead of leaving the flames running.
|
|
bool canAct = RaceInput.Allowed;
|
|
|
|
// Fire attack on Right Click
|
|
if (canAct && RaceInput.AttackHeld(1))
|
|
{
|
|
if (Player.m_localPlayer.GetEitr() > 0)
|
|
{
|
|
if (!isShootingFire)
|
|
{
|
|
StartFire();
|
|
}
|
|
else
|
|
{
|
|
UpdateFire();
|
|
}
|
|
}
|
|
else if (isShootingFire)
|
|
{
|
|
StopFire();
|
|
}
|
|
}
|
|
else if (isShootingFire)
|
|
{
|
|
StopFire();
|
|
}
|
|
|
|
if (canAct && FenrirConfig.HowlKey.Value.IsDownIgnoringHeldKeys())
|
|
{
|
|
StartCoroutine(HowlRoutine());
|
|
}
|
|
|
|
// Attacks on Left Click
|
|
if (canAct && RaceInput.AttackDown(0) && !isShootingFire)
|
|
{
|
|
StartCoroutine(ClawRoutine()); // Single claw
|
|
}
|
|
// Double claw on Middle Click
|
|
else if (canAct && RaceInput.AttackDown(2) && !isShootingFire)
|
|
{
|
|
StartCoroutine(DoubleClawRoutine());
|
|
}
|
|
}
|
|
else if (isShootingFire)
|
|
{
|
|
StopFire();
|
|
}
|
|
}
|
|
}
|
|
|
|
private void PlaySFX(params string[] prefabNames)
|
|
{
|
|
foreach (string name in prefabNames)
|
|
{
|
|
GameObject sfx = PrefabManager.Cache.GetPrefab<GameObject>(name);
|
|
if (sfx != null)
|
|
{
|
|
Instantiate(sfx, Player.m_localPlayer.transform.position, Quaternion.identity);
|
|
return;
|
|
}
|
|
}
|
|
Jotunn.Logger.LogWarning($"[CultistForm] Nessun suono trovato tra: {string.Join(", ", prefabNames)}");
|
|
}
|
|
|
|
private IEnumerator HowlRoutine()
|
|
{
|
|
isAttacking = true;
|
|
|
|
cultistAnim.SetFloat("forward_speed", 0f);
|
|
cultistAnim.SetFloat("sideway_speed", 0f);
|
|
|
|
// Cultist ha una vera e propria animazione di "taunt"
|
|
cultistAnim.SetTrigger("attack_taunt");
|
|
|
|
FenrirCreatureSound.PlayHowl("Fenring_Cultist", Player.m_localPlayer.transform.position);
|
|
|
|
// Durata approssimativa dell'animazione di taunt
|
|
yield return new WaitForSeconds(2.0f);
|
|
|
|
isAttacking = false;
|
|
}
|
|
|
|
private GameObject fireEffectInstance;
|
|
|
|
private void StartFire()
|
|
{
|
|
if (Player.m_localPlayer == null || isShootingFire) return;
|
|
|
|
isShootingFire = true;
|
|
cultistAnim.SetFloat("forward_speed", 0f);
|
|
cultistAnim.SetFloat("sideway_speed", 0f);
|
|
cultistAnim.SetBool("attack_fire", true);
|
|
|
|
PlaySFX("sfx_cultist_attack_fire_start");
|
|
cultistAnim.SetTrigger("attack_flames");
|
|
|
|
if (ZNetScene.instance != null && fireEffectInstance == null)
|
|
{
|
|
// Un effetto che dura nel tempo, trovato dai log!
|
|
GameObject fireVfx = ZNetScene.instance.GetPrefab("fx_fenring_flames");
|
|
if (fireVfx != null)
|
|
{
|
|
fireEffectInstance = Instantiate(fireVfx, Player.m_localPlayer.transform.position + Vector3.up * 1.5f + Player.m_localPlayer.transform.forward, Player.m_localPlayer.transform.rotation, Player.m_localPlayer.transform);
|
|
|
|
// Aumentiamo la durata delle particelle del 20%
|
|
ParticleSystem[] pss = fireEffectInstance.GetComponentsInChildren<ParticleSystem>();
|
|
foreach (ParticleSystem ps in pss)
|
|
{
|
|
var main = ps.main;
|
|
main.startLifetimeMultiplier *= 1.2f;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private void UpdateFire()
|
|
{
|
|
Player.m_localPlayer.UseEitr(FenrirConfig.CultistFireEitrDrainPerSecond.Value * Time.deltaTime);
|
|
cultistAnim.SetFloat("forward_speed", 0f);
|
|
cultistAnim.SetFloat("sideway_speed", 0f);
|
|
|
|
fireTimer += Time.deltaTime;
|
|
if (fireTimer >= 0.2f) // Damage tick every 0.2s
|
|
{
|
|
fireTimer = 0f;
|
|
ExecuteFireDamage();
|
|
}
|
|
}
|
|
|
|
private void StopFire()
|
|
{
|
|
isShootingFire = false;
|
|
cultistAnim.ResetTrigger("attack_flames");
|
|
|
|
if (fireEffectInstance != null)
|
|
{
|
|
Destroy(fireEffectInstance);
|
|
fireEffectInstance = null;
|
|
}
|
|
}
|
|
|
|
private void ExecuteFireDamage()
|
|
{
|
|
if (Player.m_localPlayer == null) return;
|
|
|
|
Vector3 playerPos = Player.m_localPlayer.transform.position;
|
|
Vector3 attackPoint = playerPos + Player.m_localPlayer.transform.forward * 2.5f + Vector3.up * 1f;
|
|
float attackRadius = FenrirConfig.CultistFireAttackRadius.Value;
|
|
|
|
float magicSkillLevel = Player.m_localPlayer.GetSkillLevel(Skills.SkillType.ElementalMagic);
|
|
float baseFireDamage = FenrirConfig.CultistFireDamagePerTick.Value;
|
|
float totalDamage = baseFireDamage + (magicSkillLevel * FenrirConfig.CultistFireMagicSkillScaling.Value);
|
|
|
|
int layerMask = LayerMask.GetMask("Default", "static_solid", "Default_small", "piece", "piece_nonsolid", "terrain", "character", "character_net", "character_ghost", "hitbox", "character_noenv", "vehicle");
|
|
Collider[] hits = Physics.OverlapSphere(attackPoint, attackRadius, layerMask);
|
|
System.Collections.Generic.HashSet<GameObject> hitObjects = new System.Collections.Generic.HashSet<GameObject>();
|
|
|
|
foreach (Collider hit in hits)
|
|
{
|
|
if (hit.gameObject == Player.m_localPlayer.gameObject) continue;
|
|
if (hit.attachedRigidbody != null && hit.attachedRigidbody.gameObject == Player.m_localPlayer.gameObject) continue;
|
|
|
|
IDestructible target = hit.GetComponentInParent<IDestructible>();
|
|
|
|
if (target != null)
|
|
{
|
|
Character characterTarget = target as Character;
|
|
if (characterTarget != null && characterTarget == Player.m_localPlayer) continue;
|
|
|
|
GameObject targetObj = (target as MonoBehaviour)?.gameObject;
|
|
if (targetObj != null)
|
|
{
|
|
if (hitObjects.Contains(targetObj)) continue;
|
|
hitObjects.Add(targetObj);
|
|
}
|
|
|
|
Vector3 targetCenter = hit.bounds.center;
|
|
Vector3 dirToTarget = (targetCenter - playerPos).normalized;
|
|
|
|
float angle = Vector3.Angle(Player.m_localPlayer.transform.forward, dirToTarget);
|
|
if (angle < 45f)
|
|
{
|
|
HitData hitData = new HitData();
|
|
hitData.m_damage.m_fire = totalDamage;
|
|
hitData.m_point = targetCenter;
|
|
hitData.m_dir = Player.m_localPlayer.transform.forward;
|
|
hitData.m_skill = Skills.SkillType.ElementalMagic;
|
|
hitData.m_dodgeable = true;
|
|
hitData.m_blockable = true;
|
|
hitData.m_hitType = HitData.HitType.PlayerHit;
|
|
hitData.SetAttacker(Player.m_localPlayer);
|
|
|
|
target.Damage(hitData);
|
|
|
|
if (ZNetScene.instance != null)
|
|
{
|
|
GameObject hitFx = ZNetScene.instance.GetPrefab("vfx_FireballHit");
|
|
if (hitFx != null) Instantiate(hitFx, targetCenter, Quaternion.identity);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private IEnumerator ClawRoutine()
|
|
{
|
|
isAttacking = true;
|
|
|
|
cultistAnim.SetFloat("forward_speed", 0f);
|
|
cultistAnim.SetFloat("sideway_speed", 0f);
|
|
|
|
// Per il Cultista usiamo esplicitamente il trigger dell'artigliata
|
|
cultistAnim.SetTrigger("attack_claw");
|
|
|
|
yield return new WaitForSeconds(0.4f);
|
|
|
|
PlaySFX("sfx_cultist_attack", "sfx_fenring_attack", "sfx_wolf_attack");
|
|
|
|
ExecuteClawDamage(FenrirConfig.CultistClawDamage.Value);
|
|
|
|
float remainingTimeToIdle = 0.5f - 0.4f;
|
|
if (remainingTimeToIdle > 0)
|
|
{
|
|
yield return new WaitForSeconds(remainingTimeToIdle);
|
|
}
|
|
|
|
cultistAnim.ResetTrigger("attack_claw");
|
|
isAttacking = false;
|
|
}
|
|
|
|
private IEnumerator DoubleClawRoutine()
|
|
{
|
|
isAttacking = true;
|
|
|
|
cultistAnim.SetFloat("forward_speed", 0f);
|
|
cultistAnim.SetFloat("sideway_speed", 0f);
|
|
|
|
cultistAnim.SetTrigger("attack_claw_double");
|
|
|
|
// L'animazione double claw è più lunga, facciamo il danno un po' dopo
|
|
yield return new WaitForSeconds(0.6f);
|
|
|
|
PlaySFX("sfx_cultist_attack_double", "sfx_cultist_attack", "sfx_fenring_attack");
|
|
|
|
ExecuteClawDamage(FenrirConfig.CultistDoubleClawDamage.Value);
|
|
|
|
// Attendiamo che l'animazione finisca (locking del giocatore)
|
|
// L'animazione doppia del cultista dura circa 1.5 - 2 secondi
|
|
yield return new WaitForSeconds(1.2f);
|
|
|
|
cultistAnim.ResetTrigger("attack_claw_double");
|
|
isAttacking = false;
|
|
}
|
|
|
|
private void ExecuteClawDamage(float baseDamage)
|
|
{
|
|
if (Player.m_localPlayer == null) return;
|
|
|
|
Vector3 playerPos = Player.m_localPlayer.transform.position;
|
|
Vector3 attackPoint = playerPos + Player.m_localPlayer.transform.forward * 1.5f + Vector3.up * 1f;
|
|
float attackRadius = FenrirConfig.CultistAttackRadius.Value;
|
|
|
|
float unarmedSkillLevel = Player.m_localPlayer.GetSkillLevel(Skills.SkillType.Unarmed);
|
|
float totalDamage = baseDamage + unarmedSkillLevel;
|
|
|
|
int layerMask = LayerMask.GetMask("Default", "static_solid", "Default_small", "piece", "piece_nonsolid", "terrain", "character", "character_net", "character_ghost", "hitbox", "character_noenv", "vehicle");
|
|
|
|
Collider[] hits = Physics.OverlapSphere(attackPoint, attackRadius, layerMask);
|
|
System.Collections.Generic.HashSet<GameObject> hitObjects = new System.Collections.Generic.HashSet<GameObject>();
|
|
|
|
foreach (Collider hit in hits)
|
|
{
|
|
if (hit.gameObject == Player.m_localPlayer.gameObject) continue;
|
|
if (hit.attachedRigidbody != null && hit.attachedRigidbody.gameObject == Player.m_localPlayer.gameObject) continue;
|
|
|
|
IDestructible target = hit.GetComponentInParent<IDestructible>();
|
|
|
|
if (target != null)
|
|
{
|
|
Character characterTarget = target as Character;
|
|
if (characterTarget != null && characterTarget == Player.m_localPlayer) continue;
|
|
|
|
GameObject targetObj = (target as MonoBehaviour)?.gameObject;
|
|
if (targetObj != null)
|
|
{
|
|
if (hitObjects.Contains(targetObj)) continue;
|
|
hitObjects.Add(targetObj);
|
|
}
|
|
|
|
Vector3 targetCenter = hit.bounds.center;
|
|
Vector3 dirToTarget = (targetCenter - playerPos).normalized;
|
|
|
|
float angle = Vector3.Angle(Player.m_localPlayer.transform.forward, dirToTarget);
|
|
if (angle < 70f)
|
|
{
|
|
Vector3 eyePos = playerPos + Vector3.up * 1.5f;
|
|
if (!Physics.Linecast(eyePos, targetCenter, out RaycastHit rayHit, LayerMask.GetMask("Default", "static_solid", "terrain", "piece")))
|
|
{
|
|
HitData hitData = new HitData();
|
|
hitData.m_damage.m_slash = totalDamage;
|
|
hitData.m_pushForce = FenrirConfig.CultistPushForce.Value;
|
|
hitData.m_point = targetCenter;
|
|
hitData.m_dir = Player.m_localPlayer.transform.forward;
|
|
hitData.m_skill = Skills.SkillType.Unarmed;
|
|
hitData.m_dodgeable = true;
|
|
hitData.m_blockable = true;
|
|
hitData.m_hitType = HitData.HitType.PlayerHit;
|
|
hitData.m_toolTier = 0;
|
|
hitData.SetAttacker(Player.m_localPlayer);
|
|
|
|
target.Damage(hitData);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public class WolfFormBehavior : MonoBehaviour
|
|
{
|
|
private Animator playerAnim;
|
|
private Animator wolfAnim;
|
|
private bool isAttacking = false;
|
|
|
|
void Start()
|
|
{
|
|
playerAnim = Player.m_localPlayer.transform.Find("Visual").GetComponent<Animator>();
|
|
wolfAnim = GetComponent<Animator>();
|
|
|
|
if (wolfAnim == null) wolfAnim = GetComponentInChildren<Animator>();
|
|
}
|
|
|
|
void Update()
|
|
{
|
|
if (playerAnim == null || wolfAnim == null) return;
|
|
|
|
if (!isAttacking)
|
|
{
|
|
bool isGrounded = playerAnim.GetBool("onGround");
|
|
|
|
try { wolfAnim.SetBool("onGround", isGrounded); } catch {}
|
|
try { wolfAnim.SetBool("inWater", playerAnim.GetBool("inWater")); } catch {}
|
|
|
|
if (!isGrounded)
|
|
{
|
|
try { wolfAnim.SetFloat("forward_speed", 0f); } catch {}
|
|
try { wolfAnim.SetFloat("sideway_speed", 0f); } catch {}
|
|
}
|
|
else
|
|
{
|
|
if (Player.m_localPlayer.IsCrouching())
|
|
{
|
|
try { wolfAnim.SetFloat("forward_speed", 0f); } catch {}
|
|
try { wolfAnim.SetFloat("sideway_speed", 0f); } catch {}
|
|
}
|
|
else
|
|
{
|
|
try { wolfAnim.SetFloat("forward_speed", playerAnim.GetFloat("forward_speed")); } catch {}
|
|
try { wolfAnim.SetFloat("sideway_speed", playerAnim.GetFloat("sideway_speed")); } catch {}
|
|
}
|
|
}
|
|
|
|
if (isGrounded && RaceInput.Allowed)
|
|
{
|
|
if (RaceInput.AttackDown(0)) // Left Click
|
|
{
|
|
StartCoroutine(WolfAttackRoutine("attack1", FenrirConfig.WolfAttack1Damage.Value, 0.6f, 0.2f));
|
|
}
|
|
else if (RaceInput.AttackDown(1)) // Right Click
|
|
{
|
|
StartCoroutine(WolfAttackRoutine("attack2", FenrirConfig.WolfAttack2Damage.Value, 0.8f, 0.3f));
|
|
}
|
|
else if (RaceInput.AttackDown(2)) // Middle Click
|
|
{
|
|
StartCoroutine(WolfAttackRoutine("attack3", FenrirConfig.WolfAttack3Damage.Value, 1.0f, 0.4f));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private void PlaySFX(params string[] prefabNames)
|
|
{
|
|
foreach (string name in prefabNames)
|
|
{
|
|
GameObject sfx = PrefabManager.Cache.GetPrefab<GameObject>(name);
|
|
if (sfx != null)
|
|
{
|
|
Instantiate(sfx, Player.m_localPlayer.transform.position, Quaternion.identity);
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
|
|
private IEnumerator WolfAttackRoutine(string triggerName, float baseDamage, float lockDuration, float dmgDelay)
|
|
{
|
|
isAttacking = true;
|
|
|
|
try { wolfAnim.SetFloat("forward_speed", 0f); } catch {}
|
|
try { wolfAnim.SetFloat("sideway_speed", 0f); } catch {}
|
|
|
|
wolfAnim.SetTrigger(triggerName);
|
|
|
|
yield return new WaitForSeconds(dmgDelay);
|
|
|
|
if (ZNetScene.instance != null)
|
|
{
|
|
GameObject attackSfx = ZNetScene.instance.GetPrefab("sfx_wolf_attack");
|
|
if (attackSfx != null)
|
|
{
|
|
Instantiate(attackSfx, Player.m_localPlayer.transform.position, Quaternion.identity);
|
|
}
|
|
}
|
|
|
|
ExecuteBiteDamage(baseDamage);
|
|
|
|
float remainingTimeToIdle = lockDuration - dmgDelay;
|
|
if (remainingTimeToIdle > 0)
|
|
{
|
|
yield return new WaitForSeconds(remainingTimeToIdle);
|
|
}
|
|
|
|
wolfAnim.ResetTrigger(triggerName);
|
|
isAttacking = false;
|
|
}
|
|
|
|
private void ExecuteBiteDamage(float baseDamage)
|
|
{
|
|
if (Player.m_localPlayer == null) return;
|
|
|
|
Vector3 playerPos = Player.m_localPlayer.transform.position;
|
|
// Il lupo è basso, abbassiamo l'altezza dell'attacco
|
|
Vector3 attackPoint = playerPos + Player.m_localPlayer.transform.forward * 1.5f + Vector3.up * 0.5f;
|
|
float attackRadius = FenrirConfig.WolfAttackRadius.Value;
|
|
|
|
float unarmedSkillLevel = Player.m_localPlayer.GetSkillLevel(Skills.SkillType.Unarmed);
|
|
float totalDamage = baseDamage + unarmedSkillLevel;
|
|
|
|
int layerMask = LayerMask.GetMask("Default", "static_solid", "Default_small", "piece", "piece_nonsolid", "terrain", "character", "character_net", "character_ghost", "hitbox", "character_noenv", "vehicle");
|
|
|
|
Collider[] hits = Physics.OverlapSphere(attackPoint, attackRadius, layerMask);
|
|
System.Collections.Generic.HashSet<GameObject> hitObjects = new System.Collections.Generic.HashSet<GameObject>();
|
|
|
|
foreach (Collider hit in hits)
|
|
{
|
|
if (hit.gameObject == Player.m_localPlayer.gameObject) continue;
|
|
if (hit.attachedRigidbody != null && hit.attachedRigidbody.gameObject == Player.m_localPlayer.gameObject) continue;
|
|
|
|
IDestructible target = hit.GetComponentInParent<IDestructible>();
|
|
|
|
if (target != null)
|
|
{
|
|
Character characterTarget = target as Character;
|
|
if (characterTarget != null && characterTarget == Player.m_localPlayer) continue;
|
|
|
|
GameObject targetObj = (target as MonoBehaviour)?.gameObject;
|
|
if (targetObj != null)
|
|
{
|
|
if (hitObjects.Contains(targetObj)) continue;
|
|
hitObjects.Add(targetObj);
|
|
}
|
|
|
|
Vector3 targetCenter = hit.bounds.center;
|
|
Vector3 dirToTarget = (targetCenter - playerPos).normalized;
|
|
|
|
float angle = Vector3.Angle(Player.m_localPlayer.transform.forward, dirToTarget);
|
|
if (angle < 70f)
|
|
{
|
|
Vector3 eyePos = playerPos + Vector3.up * 1.0f;
|
|
if (!Physics.Linecast(eyePos, targetCenter, out RaycastHit rayHit, LayerMask.GetMask("Default", "static_solid", "terrain", "piece")))
|
|
{
|
|
HitData hitData = new HitData();
|
|
hitData.m_damage.m_slash = totalDamage;
|
|
hitData.m_pushForce = FenrirConfig.WolfPushForce.Value;
|
|
hitData.m_point = targetCenter;
|
|
hitData.m_dir = Player.m_localPlayer.transform.forward;
|
|
hitData.m_skill = Skills.SkillType.Unarmed;
|
|
hitData.m_dodgeable = true;
|
|
hitData.m_blockable = true;
|
|
hitData.m_hitType = HitData.HitType.PlayerHit;
|
|
hitData.m_toolTier = 0;
|
|
hitData.SetAttacker(Player.m_localPlayer);
|
|
|
|
target.Damage(hitData);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// --- CLASSE CUSTOM PER L'ULV ---
|
|
public class UlvFormBehavior : MonoBehaviour
|
|
{
|
|
private Animator playerAnim;
|
|
private Animator ulvAnim;
|
|
|
|
private bool isAttacking = false;
|
|
|
|
void Start()
|
|
{
|
|
playerAnim = Player.m_localPlayer.transform.Find("Visual").GetComponent<Animator>();
|
|
ulvAnim = GetComponent<Animator>();
|
|
if (ulvAnim == null) ulvAnim = GetComponentInChildren<Animator>();
|
|
}
|
|
|
|
void Update()
|
|
{
|
|
if (Player.m_localPlayer == null || playerAnim == null || ulvAnim == null) return;
|
|
|
|
if (!isAttacking)
|
|
{
|
|
bool isGrounded = playerAnim.GetBool("onGround");
|
|
|
|
try { ulvAnim.SetBool("onGround", isGrounded); } catch {}
|
|
try { ulvAnim.SetBool("inWater", playerAnim.GetBool("inWater")); } catch {}
|
|
|
|
if (!isGrounded)
|
|
{
|
|
try { ulvAnim.SetFloat("forward_speed", 0f); } catch {}
|
|
try { ulvAnim.SetFloat("sideway_speed", 0f); } catch {}
|
|
}
|
|
else
|
|
{
|
|
if (Player.m_localPlayer.IsCrouching())
|
|
{
|
|
try { ulvAnim.SetFloat("forward_speed", 0f); } catch {}
|
|
try { ulvAnim.SetFloat("sideway_speed", 0f); } catch {}
|
|
}
|
|
else
|
|
{
|
|
try { ulvAnim.SetFloat("forward_speed", playerAnim.GetFloat("forward_speed")); } catch {}
|
|
try { ulvAnim.SetFloat("sideway_speed", playerAnim.GetFloat("sideway_speed")); } catch {}
|
|
}
|
|
}
|
|
|
|
if (isGrounded && RaceInput.Allowed)
|
|
{
|
|
if (RaceInput.AttackDown(0)) // Left Click
|
|
{
|
|
StartCoroutine(UlvAttackRoutine("attack_bite", FenrirConfig.UlvBiteDamage.Value, 0.6f, 0.2f));
|
|
}
|
|
else if (RaceInput.AttackDown(1)) // Right Click
|
|
{
|
|
// Right click uses bite but as a heavier attack since slash is moved to jump
|
|
StartCoroutine(UlvAttackRoutine("attack_bite", FenrirConfig.UlvHeavyBiteDamage.Value, 0.8f, 0.3f));
|
|
}
|
|
else if (RaceInput.AttackDown(2)) // Middle Click
|
|
{
|
|
StartCoroutine(UlvJumpAttackRoutine());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private void PlaySFX(params string[] prefabNames)
|
|
{
|
|
foreach (string name in prefabNames)
|
|
{
|
|
GameObject sfx = PrefabManager.Cache.GetPrefab<GameObject>(name);
|
|
if (sfx != null)
|
|
{
|
|
Instantiate(sfx, Player.m_localPlayer.transform.position, Quaternion.identity);
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
|
|
private IEnumerator UlvAttackRoutine(string triggerName, float baseDamage, float lockDuration, float dmgDelay)
|
|
{
|
|
isAttacking = true;
|
|
|
|
try { ulvAnim.SetFloat("forward_speed", 0f); } catch {}
|
|
try { ulvAnim.SetFloat("sideway_speed", 0f); } catch {}
|
|
|
|
try { ulvAnim.SetTrigger(triggerName); } catch {}
|
|
|
|
// Scegli il suono appropriato per l'attacco
|
|
if (triggerName == "attack_bite")
|
|
{
|
|
PlaySFX("sfx_ulv_attack", "sfx_wolf_attack", "sfx_fenring_attack");
|
|
}
|
|
else
|
|
{
|
|
PlaySFX("sfx_ulv_attack", "sfx_wolf_attack", "sfx_fenring_attack");
|
|
}
|
|
|
|
yield return new WaitForSeconds(dmgDelay);
|
|
|
|
if (ZNetScene.instance != null)
|
|
{
|
|
GameObject attackSfx = ZNetScene.instance.GetPrefab("sfx_wood_hit");
|
|
if (attackSfx != null)
|
|
{
|
|
Instantiate(attackSfx, Player.m_localPlayer.transform.position, Quaternion.identity);
|
|
}
|
|
}
|
|
|
|
ExecuteBiteDamage(baseDamage);
|
|
|
|
float remainingTimeToIdle = lockDuration - dmgDelay;
|
|
if (remainingTimeToIdle > 0)
|
|
{
|
|
yield return new WaitForSeconds(remainingTimeToIdle);
|
|
}
|
|
|
|
try { ulvAnim.ResetTrigger(triggerName); } catch {}
|
|
isAttacking = false;
|
|
}
|
|
|
|
private void ExecuteBiteDamage(float baseDamage)
|
|
{
|
|
if (Player.m_localPlayer == null) return;
|
|
|
|
Vector3 playerPos = Player.m_localPlayer.transform.position;
|
|
Vector3 attackPoint = playerPos + Player.m_localPlayer.transform.forward * 1.5f + Vector3.up * 0.5f;
|
|
float attackRadius = FenrirConfig.UlvAttackRadius.Value;
|
|
|
|
float unarmedSkillLevel = Player.m_localPlayer.GetSkillLevel(Skills.SkillType.Unarmed);
|
|
float totalDamage = baseDamage + unarmedSkillLevel;
|
|
|
|
int layerMask = LayerMask.GetMask("Default", "static_solid", "Default_small", "piece", "piece_nonsolid", "terrain", "character", "character_net", "character_ghost", "hitbox", "character_noenv", "vehicle");
|
|
|
|
Collider[] hits = Physics.OverlapSphere(attackPoint, attackRadius, layerMask);
|
|
System.Collections.Generic.HashSet<GameObject> hitObjects = new System.Collections.Generic.HashSet<GameObject>();
|
|
|
|
foreach (Collider hit in hits)
|
|
{
|
|
if (hit.gameObject == Player.m_localPlayer.gameObject) continue;
|
|
if (hit.attachedRigidbody != null && hit.attachedRigidbody.gameObject == Player.m_localPlayer.gameObject) continue;
|
|
|
|
IDestructible target = hit.GetComponentInParent<IDestructible>();
|
|
|
|
if (target != null)
|
|
{
|
|
Character characterTarget = target as Character;
|
|
if (characterTarget != null && characterTarget == Player.m_localPlayer) continue;
|
|
|
|
GameObject targetObj = (target as MonoBehaviour)?.gameObject;
|
|
if (targetObj != null)
|
|
{
|
|
if (hitObjects.Contains(targetObj)) continue;
|
|
hitObjects.Add(targetObj);
|
|
}
|
|
|
|
Vector3 targetCenter = hit.bounds.center;
|
|
Vector3 dirToTarget = (targetCenter - playerPos).normalized;
|
|
|
|
float angle = Vector3.Angle(Player.m_localPlayer.transform.forward, dirToTarget);
|
|
if (angle < 70f)
|
|
{
|
|
Vector3 eyePos = playerPos + Vector3.up * 1.0f;
|
|
if (!Physics.Linecast(eyePos, targetCenter, out RaycastHit rayHit, LayerMask.GetMask("Default", "static_solid", "terrain", "piece")))
|
|
{
|
|
HitData hitData = new HitData();
|
|
hitData.m_damage.m_slash = totalDamage;
|
|
hitData.m_pushForce = FenrirConfig.UlvPushForce.Value;
|
|
hitData.m_point = targetCenter;
|
|
hitData.m_dir = Player.m_localPlayer.transform.forward;
|
|
hitData.m_skill = Skills.SkillType.Unarmed;
|
|
hitData.m_dodgeable = true;
|
|
hitData.m_blockable = true;
|
|
hitData.m_hitType = HitData.HitType.PlayerHit;
|
|
hitData.m_toolTier = 0;
|
|
hitData.SetAttacker(Player.m_localPlayer);
|
|
|
|
target.Damage(hitData);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private IEnumerator UlvJumpAttackRoutine()
|
|
{
|
|
isAttacking = true;
|
|
|
|
try { ulvAnim.SetFloat("forward_speed", 0f); } catch {}
|
|
try { ulvAnim.SetFloat("sideway_speed", 0f); } catch {}
|
|
|
|
try { ulvAnim.SetTrigger("attack_slash"); } catch {}
|
|
PlaySFX("sfx_ulv_attack", "sfx_wolf_attack");
|
|
|
|
yield return new WaitForSeconds(0.3f); // Wait 0.3s before leaping
|
|
|
|
// Leap forward (+50% range)
|
|
float leapDuration = 0.25f;
|
|
float leapSpeed = FenrirConfig.UlvLeapSpeed.Value;
|
|
float elapsed = 0f;
|
|
|
|
while (elapsed < leapDuration)
|
|
{
|
|
if (Player.m_localPlayer != null)
|
|
{
|
|
Vector3 moveDir = Player.m_localPlayer.transform.forward;
|
|
Player.m_localPlayer.transform.position += moveDir * leapSpeed * Time.deltaTime;
|
|
}
|
|
elapsed += Time.deltaTime;
|
|
yield return null;
|
|
}
|
|
|
|
if (ZNetScene.instance != null)
|
|
{
|
|
GameObject attackSfx = ZNetScene.instance.GetPrefab("sfx_wood_hit");
|
|
if (attackSfx != null)
|
|
{
|
|
Instantiate(attackSfx, Player.m_localPlayer.transform.position, Quaternion.identity);
|
|
}
|
|
}
|
|
|
|
ExecuteBiteDamage(FenrirConfig.UlvJumpAttackDamage.Value);
|
|
|
|
yield return new WaitForSeconds(0.4f);
|
|
|
|
try { ulvAnim.ResetTrigger("attack_slash"); } catch {}
|
|
isAttacking = false;
|
|
}
|
|
}
|
|
|
|
}
|