277 lines
6.4 KiB
C#
277 lines
6.4 KiB
C#
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using DarkTonic.MasterAudio;
|
|
using DragonLi.Core;
|
|
using DragonLi.Frame;
|
|
using Mirror;
|
|
using UnityEngine;
|
|
using UnityEngine.XR;
|
|
using Valheim;
|
|
|
|
|
|
public class LoveStaff : Weapon
|
|
{
|
|
public Transform Bottom;
|
|
public Transform Top;
|
|
/// <summary>
|
|
/// 激光特效
|
|
/// </summary>
|
|
public GameObject Laser;
|
|
/// <summary>
|
|
/// 激光子弹
|
|
/// </summary>
|
|
public GameObject laserRayPre;
|
|
public InputDevice rightHandDevice;
|
|
public AudioSource audioSource;
|
|
public AudioClip ChargedEnergClip;
|
|
[Header("选中目标图层")]
|
|
public LayerMask HitLayer;
|
|
[Header("攻击目标图层")]
|
|
public LayerMask AttackHitLayer;
|
|
[SyncVar]
|
|
public bool IsComplete;
|
|
/// <summary>
|
|
/// 是否攻击到目标
|
|
/// </summary>
|
|
public bool IsAttacking = false;
|
|
|
|
private bool _isClick = false;
|
|
|
|
/// <summary>
|
|
/// 当前目标
|
|
/// </summary>
|
|
public Pet Pet = null;
|
|
|
|
public List<Pet> HitPets = new List<Pet>();
|
|
|
|
private GameObject CureRay;
|
|
|
|
/// <summary>
|
|
/// 击中特效
|
|
/// </summary>
|
|
public GameObject HeartLightImpact;
|
|
|
|
|
|
/// <summary>
|
|
/// 设置一个宠物焦点
|
|
/// </summary>
|
|
public void SetPetFocus()
|
|
{
|
|
RaycastHit handlingHit;
|
|
if (Physics.Raycast(Top.position, Top.forward, out handlingHit, 15F, HitLayer))
|
|
{
|
|
Pet = handlingHit.collider.GetComponent<Pet>();
|
|
if (HitPets.Count > 0 && !HitPets.Any(pet => pet.id == Pet.id))
|
|
{
|
|
HitPets.Add(Pet);
|
|
}
|
|
|
|
if (Pet != null && Pet.state != PetState.NotRescue)
|
|
{
|
|
// Pet.SetOutLine(1.5F);
|
|
GameManager.Ins.SetOutLine(2);
|
|
}
|
|
// foreach (var pet in HitPets)
|
|
// {
|
|
// if (pet != null && pet.state != PetState.NotRescue && Pet.id == pet.id)
|
|
// {
|
|
// pet.SetOutLine(1.5F);
|
|
// }
|
|
// else
|
|
// {
|
|
// pet.SetOutLine(0);
|
|
// }
|
|
// }
|
|
}
|
|
else
|
|
{
|
|
GameManager.Ins.SetAllPetOutLineToZero();
|
|
// foreach (var pet in HitPets)
|
|
// {
|
|
// if (pet != null && pet.state != PetState.NotRescue && Pet.id == pet.id)
|
|
// {
|
|
// pet.SetOutLine(1.5F);
|
|
// }
|
|
// else
|
|
// {
|
|
// pet.SetOutLine(0);
|
|
// }
|
|
// }
|
|
Pet = null;
|
|
|
|
}
|
|
Vector3 origin = Top.position;
|
|
Vector3 direction = Top.forward;
|
|
Debug.DrawRay(origin, direction * 15f, Color.green);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 敲击
|
|
/// </summary>
|
|
public void KnockAttack()
|
|
{
|
|
|
|
if (Physics.Raycast(Bottom.position, Bottom.up, out RaycastHit handlingHit, 1F, AttackHitLayer))
|
|
{
|
|
Enemy enemy = handlingHit.collider.GetComponent<Enemy>();
|
|
if (enemy != null && !IsAttacking)
|
|
{
|
|
Debug.Log("TO 攻击到目标");
|
|
IsAttacking = true;
|
|
enemy.KnockTakeDamage(1F, handlingHit.point);
|
|
//播放动画
|
|
enemy.PlayTakeDamageAnim();
|
|
|
|
}
|
|
}
|
|
else
|
|
{
|
|
IsAttacking = false;
|
|
Debug.Log("TO 没有目标");
|
|
}
|
|
Vector3 origin = Bottom.position;
|
|
Vector3 direction = Bottom.up;
|
|
Debug.DrawRay(origin, direction * 1F, Color.blue);
|
|
}
|
|
|
|
[Command]
|
|
public void CommandKncok()
|
|
{
|
|
KnockAttack();
|
|
}
|
|
public void Start()
|
|
{
|
|
#if !UNITY_EDITOR
|
|
rightHandDevice = InputDevices.GetDeviceAtXRNode(XRNode.RightHand);
|
|
#endif
|
|
}
|
|
public new void Update()
|
|
{
|
|
base.Update();
|
|
if (!isOwned)
|
|
{
|
|
return;
|
|
}
|
|
SetPetFocus();
|
|
CommandKncok();
|
|
//打出一条射线
|
|
#if UNITY_EDITOR
|
|
// 蓄力施放
|
|
if (Input.GetKey(KeyCode.Q))
|
|
{
|
|
if (Pet == null)
|
|
{
|
|
HideLaserEffect();
|
|
audioSource.Stop();
|
|
}
|
|
else if (Pet.state != PetState.NotRescue)
|
|
{
|
|
Shot();
|
|
}
|
|
}
|
|
// 技能结束
|
|
if (Input.GetKeyUp(KeyCode.Q))
|
|
{
|
|
//删除射线
|
|
if (CureRay != null)
|
|
{
|
|
NetworkServer.Destroy(CureRay);
|
|
}
|
|
HideLaserEffect();
|
|
audioSource.Stop();
|
|
}
|
|
#else
|
|
bool isTrigger = false;
|
|
if (rightHandDevice != null)
|
|
{
|
|
rightHandDevice.TryGetFeatureValue(CommonUsages.triggerButton, out isTrigger);
|
|
}
|
|
if (isTrigger)
|
|
{
|
|
if (Pet == null)
|
|
{
|
|
HideLaserEffect();
|
|
}
|
|
else if (Pet.state != PetState.NotRescue)
|
|
{
|
|
Shot();
|
|
|
|
}
|
|
}
|
|
else
|
|
{
|
|
HideLaserEffect();
|
|
audioSource.Stop();
|
|
}
|
|
#endif
|
|
}
|
|
|
|
/// <summary>
|
|
/// 播放蓄力音效
|
|
/// </summary>
|
|
[Server]
|
|
public void PlayChargedEnergAudio()
|
|
{
|
|
RpcPlayChargedEnergAudio();
|
|
}
|
|
|
|
public void RpcPlayChargedEnergAudio()
|
|
{
|
|
if (!audioSource.isPlaying)
|
|
{
|
|
audioSource.PlayOneShot(ChargedEnergClip);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
[Command]
|
|
public void ShowLaserEffect()
|
|
{
|
|
RpcShowLaserEffect();
|
|
}
|
|
|
|
[ClientRpc]
|
|
public void RpcShowLaserEffect()
|
|
{
|
|
Laser.SetActive(true);
|
|
}
|
|
|
|
[Command]
|
|
public void HideLaserEffect()
|
|
{
|
|
RpcHideLaserEffect();
|
|
}
|
|
|
|
[ClientRpc]
|
|
public void RpcHideLaserEffect()
|
|
{
|
|
Laser.SetActive(false);
|
|
HeartLightImpact.SetActive(false);
|
|
}
|
|
|
|
|
|
public void Shot()
|
|
{
|
|
//播放蓄力音效
|
|
PlayChargedEnergAudio();
|
|
//播放蓄力粒子
|
|
if (Pet != null)
|
|
{
|
|
ShowLaserEffect();
|
|
RaycastHit handlingHit;
|
|
if (Physics.Raycast(Top.position, Top.forward, out handlingHit, 15F, HitLayer))
|
|
{
|
|
HeartLightImpact.transform.position = handlingHit.point;
|
|
|
|
HeartLightImpact.SetActive(true);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
HeartLightImpact.SetActive(false);
|
|
}
|
|
}
|
|
|
|
}
|