Files
valheim/Assets/_Valheim/Scripts/Skill/Skill.cs
2025-07-04 14:16:14 +08:00

61 lines
1.6 KiB
C#

using System;
using System.Collections;
using System.Collections.Generic;
using DragonLi.Frame;
using UnityEngine;
using Valheim;
using Random = UnityEngine.Random;
public class Skill : MonoBehaviour
{
public int skillID;
public bool isFinger;
public bool isEnemy;
public SkillData data;
public void Init()
{
data = GameManager.Ins.SkillDataList[skillID];
if(isEnemy)
Atk();
}
public void Atk()
{
foreach (var item in GameManager.Ins.PetList.Values)
{
if(item.state== PetState.Terminal)
continue;
IDamagable damagable = item.GetComponent<IDamagable>();
if (damagable != null)
{
float atk=Random.Range(data.MinAtk, data.MaxAtk);
Debug.LogError("宠物:"+item.name+"收到伤害:"+atk);
damagable.ApplyDamage(atk, false, transform);
//AddExp();
}
}
}
private void OnTriggerEnter(Collider other)
{
string tag =isEnemy? "Pet": "Enemy";
if(!other.CompareTag(tag))
return;
var agent = other.GetComponent<Agent>();
if(agent==null)
return;
if (data.SkillType == ESkillType.RangeAttack)
{
IDamagable damagable = agent.GetComponent<IDamagable>();
if (damagable != null)
{
float atk=Random.Range(data.MinAtk, data.MaxAtk);
damagable.ApplyDamage(atk, false, transform);
//AddExp();
}
}
}
}