UnityEngine.Input reads the device directly, so abilities bound to keys or mouse buttons kept firing with the map, the inventory, a chest, the chat or a menu open - clicking an item in a container also swung the transformed attack. Route that input through Player.TakeInput, which is what Valheim runs its own controls through and already reports false for those states (InventoryGui covers the backpack and chests alike). Aswid's transform keys were the only place already doing this; the shared helper replaces that one-off and covers Skadi's cold spell, form keys, flight toggle, form attacks and flight boost, Fenrir's form keys and the attacks of all four form behaviors, Trol's rock throw and true form, and Aswid's devour toggle. Cultist fire is a held button, so it is gated per read rather than around the block: opening a GUI mid-stream now falls through to StopFire() instead of leaving the flames running.
1034 lines
41 KiB
C#
1034 lines
41 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
|
|
{
|
|
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 (Input.GetKeyDown(KeyCode.O))
|
|
{
|
|
StartCoroutine(HowlRoutine());
|
|
}
|
|
else if (Input.GetMouseButtonDown(1)) // Tasto destro (Heavy Claw)
|
|
{
|
|
StartCoroutine(ClawRoutine("attack_claw1", 110f, 1.2f, 0.5f));
|
|
}
|
|
else if (Input.GetMouseButtonDown(0)) // Tasto sinistro
|
|
{
|
|
StartCoroutine(ClawRoutine("attack_claw0", 60f, 1.0f, 0.4f));
|
|
}
|
|
else if (Input.GetMouseButtonDown(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");
|
|
|
|
PlaySFX("sfx_wolf_howl", "sfx_wolf_alert", "sfx_fenring_idle");
|
|
|
|
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 * 31.5f;
|
|
// Spinta verso l'alto solo nella prima metà dello scatto
|
|
if (elapsedDash < dashDuration / 2f)
|
|
{
|
|
dashVelocity += Vector3.up * 13.1f;
|
|
}
|
|
|
|
rb.MovePosition(rb.position + dashVelocity * Time.fixedDeltaTime);
|
|
}
|
|
}
|
|
elapsedDash += Time.fixedDeltaTime;
|
|
yield return new WaitForFixedUpdate();
|
|
}
|
|
|
|
// Infliggiamo il danno al termine dello scatto
|
|
ExecuteClawDamage(95f);
|
|
|
|
// 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 = 2.5f;
|
|
|
|
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 = 30f;
|
|
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 && Input.GetMouseButton(1))
|
|
{
|
|
if (Player.m_localPlayer.GetEitr() > 0)
|
|
{
|
|
if (!isShootingFire)
|
|
{
|
|
StartFire();
|
|
}
|
|
else
|
|
{
|
|
UpdateFire();
|
|
}
|
|
}
|
|
else if (isShootingFire)
|
|
{
|
|
StopFire();
|
|
}
|
|
}
|
|
else if (isShootingFire)
|
|
{
|
|
StopFire();
|
|
}
|
|
|
|
if (canAct && Input.GetKeyDown(KeyCode.O))
|
|
{
|
|
StartCoroutine(HowlRoutine());
|
|
}
|
|
|
|
// Attacks on Left Click
|
|
if (canAct && Input.GetMouseButtonDown(0) && !isShootingFire)
|
|
{
|
|
StartCoroutine(ClawRoutine()); // Single claw
|
|
}
|
|
// Double claw on Middle Click
|
|
else if (canAct && Input.GetMouseButtonDown(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");
|
|
|
|
PlaySFX("sfx_wolf_howl", "sfx_wolf_alert", "sfx_fenring_idle");
|
|
|
|
// 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()
|
|
{
|
|
// Drain Eitr ridotto del 50% (da 25 a 12.5 per sec)
|
|
Player.m_localPlayer.UseEitr(12.5f * 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 = 3f;
|
|
|
|
float magicSkillLevel = Player.m_localPlayer.GetSkillLevel(Skills.SkillType.ElementalMagic);
|
|
float baseFireDamage = 20f; // per 0.2s
|
|
float totalDamage = baseFireDamage + (magicSkillLevel * 0.5f);
|
|
|
|
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(85f);
|
|
|
|
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(140f);
|
|
|
|
// 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 = 2.5f;
|
|
|
|
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 = 30f;
|
|
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 (Input.GetMouseButtonDown(0)) // Left Click
|
|
{
|
|
StartCoroutine(WolfAttackRoutine("attack1", 40f, 0.6f, 0.2f));
|
|
}
|
|
else if (Input.GetMouseButtonDown(1)) // Right Click
|
|
{
|
|
StartCoroutine(WolfAttackRoutine("attack2", 60f, 0.8f, 0.3f));
|
|
}
|
|
else if (Input.GetMouseButtonDown(2)) // Middle Click
|
|
{
|
|
StartCoroutine(WolfAttackRoutine("attack3", 80f, 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 = 2.0f;
|
|
|
|
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 = 20f;
|
|
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 (Input.GetMouseButtonDown(0)) // Left Click
|
|
{
|
|
StartCoroutine(UlvAttackRoutine("attack_bite", 40f, 0.6f, 0.2f));
|
|
}
|
|
else if (Input.GetMouseButtonDown(1)) // Right Click
|
|
{
|
|
// Right click uses bite but as a heavier attack since slash is moved to jump
|
|
StartCoroutine(UlvAttackRoutine("attack_bite", 60f, 0.8f, 0.3f));
|
|
}
|
|
else if (Input.GetMouseButtonDown(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 = 2.0f;
|
|
|
|
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 = 25f;
|
|
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 = 18f; // Increased from 12f to 18f
|
|
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(80f);
|
|
|
|
yield return new WaitForSeconds(0.4f);
|
|
|
|
try { ulvAnim.ResetTrigger("attack_slash"); } catch {}
|
|
isAttacking = false;
|
|
}
|
|
}
|
|
|
|
}
|